name: odin-ci

on:
  push:
    paths:
      - 'odin/**'
      - '.github/workflows/odin-ci.yml'
  pull_request:
    paths:
      - 'odin/**'
      - '.github/workflows/odin-ci.yml'
  workflow_dispatch:

jobs:
  build-test:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: odin
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: true

      - name: Setup Odin
        uses: laytan/setup-odin@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Build
        run: ./build.sh

      - name: Test
        run: |
          CLAY_DIR="$(pwd)/vendor/clay/bindings/odin/clay-odin"
          odin test tests -collection:clay="$CLAY_DIR"

      - name: Package
        run: ./scripts/package.sh

      - name: Upload package artifact
        uses: actions/upload-artifact@v4
        with:
          name: comic-odin-package
          path: |
            odin/dist/*.tar.gz
            odin/dist/*.sha256
