# Generated by `starci compile --target circleci` from matrix.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:
  py3-11-sqlite:
    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'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-py3-11-sqlite-007dfd24392afb1e-{{ 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: "py3.11 sqlite"
          environment:
            STARCI_RUN: |-
              pip install -e '.[test]' && pytest -q
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -e 'TEST_DATABASE=sqlite' \
              python:3.11-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-py3-11-sqlite-007dfd24392afb1e-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  py3-12-sqlite:
    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'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-py3-12-sqlite-3a9fb0a71be584d4-{{ 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: "py3.12 sqlite"
          environment:
            STARCI_RUN: |-
              pip install -e '.[test]' && pytest -q
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -e 'TEST_DATABASE=sqlite' \
              python:3.12-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-py3-12-sqlite-3a9fb0a71be584d4-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  py3-12-postgres:
    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'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-py3-12-postgres-b6222284d3cb251b-{{ 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: "py3.12 postgres"
          environment:
            STARCI_RUN: |-
              pip install -e '.[test]' && pytest -q
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -e 'TEST_DATABASE=postgres' \
              python:3.12-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-py3-12-postgres-b6222284d3cb251b-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  py3-13-sqlite:
    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'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-py3-13-sqlite-6debb66a7d4f50b0-{{ 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: "py3.13 sqlite"
          environment:
            STARCI_RUN: |-
              pip install -e '.[test]' && pytest -q
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -e 'TEST_DATABASE=sqlite' \
              python:3.13-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-py3-13-sqlite-6debb66a7d4f50b0-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  py3-13-postgres:
    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'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)pyproject.toml' ':(top,literal)src' ':(top,literal)tests' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-py3-13-postgres-fbd76783d00148fd-{{ 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: "py3.13 postgres"
          environment:
            STARCI_RUN: |-
              pip install -e '.[test]' && pytest -q
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -e 'TEST_DATABASE=postgres' \
              python:3.13-slim sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-py3-13-postgres-fbd76783d00148fd-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - py3-11-sqlite
      - py3-12-sqlite
      - py3-12-postgres
      - py3-13-sqlite
      - py3-13-postgres
