# Generated by `starci compile --target circleci` 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:
#  - `worker`, `prefer` and `avoid` have no equivalent here and are dropped
#    (integration, gpu): CircleCI chooses machines by resource class, not by
#    label. Every job uses medium.
#  - Passes are remembered in this project's CircleCI cache, which expires.
#    starci's own store does not.

version: 2.1

jobs:
  unit:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/pyproject.toml' '/src/**/*.py' '/tests/conftest.py' '/tests/test_runs.py' '/tests/test_runs2.py' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,literal)tests/conftest.py' ':(top,literal)tests/test_runs.py' ':(top,literal)tests/test_runs2.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-unit-338d1cbc9fe12195-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "unit"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run pytest -q tests/test_runs.py tests/test_runs2.py
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-unit-338d1cbc9fe12195-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  integration:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/pyproject.toml' '/src/**/*.py' '/tests/conftest.py' '/tests/integration/**/*.py' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,literal)tests/conftest.py' ':(top,glob)tests/integration/**/*.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-integration-ec5d29ab03b66540-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "integration"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run pytest -q tests/integration/**/*.py
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-integration-ec5d29ab03b66540-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  gpu:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/pyproject.toml' '/src/**/*.py' '/tests/conftest.py' '/tests/test_gpu.py' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,literal)tests/conftest.py' ':(top,literal)tests/test_gpu.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-gpu-d8edba88006f9db3-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "gpu"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run pytest -q tests/test_gpu.py
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              ghcr.io/astral-sh/uv:python3.13-bookworm-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-gpu-d8edba88006f9db3-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - unit
      - integration
      - gpu
