# Generated by `starci compile` from gpu.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
#  - `prefer` and `avoid` have no equivalent here and are dropped
#    (integration). `worker` becomes runner labels.
#  - Passes are remembered in this repository's Actions cache, which GitHub
#    scopes by branch and evicts when old. starci's own store has neither
#    limit.

name: CI

on:
  push:
    branches: ['**']
    tags: ['**']
  pull_request:
  workflow_dispatch:

jobs:
  unit:
    name: "unit"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src/**/*.py
            /tests/conftest.py
            /tests/test_runs.py
            /tests/test_runs2.py
            /uv.lock
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-unit-338d1cbc9fe12195-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src/**/*.py', 'tests/conftest.py', 'tests/conftest.py/**', 'tests/test_runs.py', 'tests/test_runs.py/**', 'tests/test_runs2.py', 'tests/test_runs2.py/**', 'uv.lock', 'uv.lock/**') }}
      - name: "unit"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            uv sync --frozen && uv run pytest -q tests/test_runs.py tests/test_runs2.py
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  integration:
    name: "integration"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src/**/*.py
            /tests/conftest.py
            /tests/integration/**/*.py
            /uv.lock
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-integration-ec5d29ab03b66540-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src/**/*.py', 'tests/conftest.py', 'tests/conftest.py/**', 'tests/integration/**/*.py', 'uv.lock', 'uv.lock/**') }}
      - name: "integration"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            uv sync --frozen && uv run pytest -q tests/integration/**/*.py
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  gpu:
    name: "gpu"
    runs-on: ["self-hosted", "gpu=true"]
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src/**/*.py
            /tests/conftest.py
            /tests/test_gpu.py
            /uv.lock
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-gpu-d8edba88006f9db3-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src/**/*.py', 'tests/conftest.py', 'tests/conftest.py/**', 'tests/test_gpu.py', 'tests/test_gpu.py/**', 'uv.lock', 'uv.lock/**') }}
      - name: "gpu"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            uv sync --frozen && uv run pytest -q tests/test_gpu.py
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
