Skip to content

matrix

A matrix is a loop, with exclusions as an if.

A matrix is a loop. Here: every supported Python against two databases, with the combinations that make no sense left out by an ordinary if.

flowchart LR
    s0["py3.11 sqlite"]
    s1["py3.12 sqlite"]
    s2["py3.12 postgres"]
    s3["py3.13 sqlite"]
    s4["py3.13 postgres"]

The steps this script plans for a push about which nothing is known. An arrow is a needs.

# A matrix is a loop. Here: every supported Python against two databases, with
# the combinations that make no sense left out by an ordinary `if`.

PYTHONS = ["3.11", "3.12", "3.13"]
DATABASES = ["sqlite", "postgres"]

def ci(ctx):
    steps = []
    for python in PYTHONS:
        for db in DATABASES:
            # Postgres support was added for 3.12; nothing to test before it.
            if db == "postgres" and python == "3.11":
                continue
            steps.append(step(
                "py{} {}".format(python, db),
                image = "python:{}-slim".format(python),
                run = "pip install -e '.[test]' && pytest -q",
                env = {"TEST_DATABASE": db},
                inputs = ["src", "tests", "pyproject.toml"],
            ))
    return steps
# Generated by `starci compile` 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 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:
  py3-11-sqlite:
    name: "py3.11 sqlite"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-py3-11-sqlite-007dfd24392afb1e-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "py3.11 sqlite"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -e '.[test]' && pytest -q
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -e 'TEST_DATABASE=sqlite' \
            python:3.11-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"

  py3-12-sqlite:
    name: "py3.12 sqlite"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-py3-12-sqlite-3a9fb0a71be584d4-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "py3.12 sqlite"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -e '.[test]' && pytest -q
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -e 'TEST_DATABASE=sqlite' \
            python:3.12-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"

  py3-12-postgres:
    name: "py3.12 postgres"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-py3-12-postgres-b6222284d3cb251b-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "py3.12 postgres"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -e '.[test]' && pytest -q
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -e 'TEST_DATABASE=postgres' \
            python:3.12-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"

  py3-13-sqlite:
    name: "py3.13 sqlite"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-py3-13-sqlite-6debb66a7d4f50b0-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "py3.13 sqlite"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -e '.[test]' && pytest -q
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -e 'TEST_DATABASE=sqlite' \
            python:3.13-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"

  py3-13-postgres:
    name: "py3.13 postgres"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /pyproject.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-py3-13-postgres-fbd76783d00148fd-${{ hashFiles('pyproject.toml', 'pyproject.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "py3.13 postgres"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -e '.[test]' && pytest -q
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -e 'TEST_DATABASE=postgres' \
            python:3.13-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"
# 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

Download: matrix.ci.star, GitHub Actions, CircleCI