# Generated by `starci compile --target circleci` from python-uv.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:
#  - Passes are remembered in this project's CircleCI cache, which expires.
#    starci's own store does not.

version: 2.1

jobs:
  format:
    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/**/*.py' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,glob)tests/**/*.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-format-9c753dc6e2fbc8d7-{{ 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: "Tool: uv"
          command: |
            mkdir -p "$HOME/starci-tools/uv"
            curl -fsSL 'https://github.com/astral-sh/uv/releases/download/0.12.1/uv-x86_64-unknown-linux-gnu.tar.gz' -o /tmp/uv.download
            echo "90b2f223fb69d19db49e117da601f64978593417988530aa733d456141b4bcbb  /tmp/uv.download" | sha256sum -c -
            tar -xf "/tmp/uv.download" -C "$HOME/starci-tools/uv"
      - run:
          name: "Image with ca-certificates, libpq5"
          command: |
            docker build -q -t starci-env-format - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates libpq5 && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: uv"
          keys:
            - starci-cache-uv-
      - run:
          name: "format"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run --no-sync ruff format --check src tests
          command: |
            image_path=$(docker image inspect starci-env-format --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/uv:/opt/starci/tools/uv:ro" \
              -v "$HOME/starci-cache/uv:/root/.cache/uv" \
              -e "PATH=/opt/starci/tools/uv/uv-x86_64-unknown-linux-gnu:$image_path" \
              starci-env-format sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: uv"
          key: starci-cache-uv-{{ .Revision }}
          paths:
            - ~/starci-cache/uv
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-format-9c753dc6e2fbc8d7-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  lint:
    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/**/*.py' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,glob)tests/**/*.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-lint-cf540252b81cbb62-{{ 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: "Tool: uv"
          command: |
            mkdir -p "$HOME/starci-tools/uv"
            curl -fsSL 'https://github.com/astral-sh/uv/releases/download/0.12.1/uv-x86_64-unknown-linux-gnu.tar.gz' -o /tmp/uv.download
            echo "90b2f223fb69d19db49e117da601f64978593417988530aa733d456141b4bcbb  /tmp/uv.download" | sha256sum -c -
            tar -xf "/tmp/uv.download" -C "$HOME/starci-tools/uv"
      - run:
          name: "Image with ca-certificates, libpq5"
          command: |
            docker build -q -t starci-env-lint - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates libpq5 && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: uv"
          keys:
            - starci-cache-uv-
      - run:
          name: "lint"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run --no-sync ruff check src tests
          command: |
            image_path=$(docker image inspect starci-env-lint --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/uv:/opt/starci/tools/uv:ro" \
              -v "$HOME/starci-cache/uv:/root/.cache/uv" \
              -e "PATH=/opt/starci/tools/uv/uv-x86_64-unknown-linux-gnu:$image_path" \
              starci-env-lint sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: uv"
          key: starci-cache-uv-{{ .Revision }}
          paths:
            - ~/starci-cache/uv
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-lint-cf540252b81cbb62-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  types:
    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' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,glob)src/**/*.py' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-types-79b1b2507054dbe7-{{ 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: "Tool: uv"
          command: |
            mkdir -p "$HOME/starci-tools/uv"
            curl -fsSL 'https://github.com/astral-sh/uv/releases/download/0.12.1/uv-x86_64-unknown-linux-gnu.tar.gz' -o /tmp/uv.download
            echo "90b2f223fb69d19db49e117da601f64978593417988530aa733d456141b4bcbb  /tmp/uv.download" | sha256sum -c -
            tar -xf "/tmp/uv.download" -C "$HOME/starci-tools/uv"
      - run:
          name: "Image with ca-certificates, libpq5"
          command: |
            docker build -q -t starci-env-types - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates libpq5 && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: uv"
          keys:
            - starci-cache-uv-
      - run:
          name: "types"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run --no-sync pyright src
          command: |
            image_path=$(docker image inspect starci-env-types --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/uv:/opt/starci/tools/uv:ro" \
              -v "$HOME/starci-cache/uv:/root/.cache/uv" \
              -e "PATH=/opt/starci/tools/uv/uv-x86_64-unknown-linux-gnu:$image_path" \
              starci-env-types sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: uv"
          key: starci-cache-uv-{{ .Revision }}
          paths:
            - ~/starci-cache/uv
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-types-79b1b2507054dbe7-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  test:
    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' '/tests' '/uv.lock'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' ':(top,literal)uv.lock' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-test-0789cd34dab1fbed-{{ 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: "Tool: uv"
          command: |
            mkdir -p "$HOME/starci-tools/uv"
            curl -fsSL 'https://github.com/astral-sh/uv/releases/download/0.12.1/uv-x86_64-unknown-linux-gnu.tar.gz' -o /tmp/uv.download
            echo "90b2f223fb69d19db49e117da601f64978593417988530aa733d456141b4bcbb  /tmp/uv.download" | sha256sum -c -
            tar -xf "/tmp/uv.download" -C "$HOME/starci-tools/uv"
      - run:
          name: "Image with ca-certificates, libpq5"
          command: |
            docker build -q -t starci-env-test - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates libpq5 && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: uv"
          keys:
            - starci-cache-uv-
      - run:
          name: "test"
          environment:
            STARCI_RUN: |-
              uv sync --frozen && uv run --no-sync pytest -q
          command: |
            image_path=$(docker image inspect starci-env-test --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/uv:/opt/starci/tools/uv:ro" \
              -v "$HOME/starci-cache/uv:/root/.cache/uv" \
              -e "PATH=/opt/starci/tools/uv/uv-x86_64-unknown-linux-gnu:$image_path" \
              starci-env-test sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: uv"
          key: starci-cache-uv-{{ .Revision }}
          paths:
            - ~/starci-cache/uv
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-test-0789cd34dab1fbed-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - format
      - lint
      - types
      - test
