Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 4.06 KB

reusable-workflows.md

File metadata and controls

62 lines (42 loc) · 4.06 KB

Python CI contract and reusable workflows

Every Python repository validates through one script, bash scripts/check.sh [lint|test], and runs it in CI through the reusable workflows of github-workflows. This repository publishes no callable workflow of its own: it ships the script and the caller workflow through the Copier template.

Table of Contents

The check script

Command Runs
bash scripts/check.sh uv sync --frozen, pre-commit on all files, pytest
bash scripts/check.sh lint uv sync --frozen, pre-commit on all files
bash scripts/check.sh test uv sync --frozen, pytest

Any other argument exits with status 2. Ruff and mypy are local pre-commit hooks run with python -m inside the uv environment, so their versions come from uv.lock alone. Pytest runs with python -P, and its coverage options live in [tool.pytest.ini_options] addopts of pyproject.toml.

The managed ci.yml

Copier renders .github/workflows/ci.yml and updates it on every copier update:

Job Calls Runs when
route pr-route.yml always
lint python-check.yml, target lint always
pytest python-check.yml, target test the route is applicable
coverage coverage.yml the route is applicable
tests-success (Tests success) gate over route, pytest, coverage always

The uses: pins live in the template, so adopters receive new github-workflows versions through copier update. Do not bump them by hand.

Reusable workflows

The inputs are documented in each callee; the ones adopters meet most:

Workflow Inputs
python-check.yml target (required, lint or test), python-version, runs-on, pre-install-command, env (KEY=VALUE lines), uv-sync-args, coverage-artifact (coverage-*), timeout-minutes
pr-route.yml rules-file, runs-on, timeout-minutes; output applicable
coverage.yml line, branch, patch (thresholds can only be raised), report-artifacts, base-ref

python-check.yml runs uv sync --locked followed by bash scripts/check.sh <target>.

Path routing

pr-route.yml reads .github/pr-route.json from the pull request base commit, with exactly the string arrays skip_files, skip_prefixes, skip_suffixes and build_inputs. applicable is false only when every changed path is listed as skippable; without the file, or with an invalid one, everything runs. The file belongs to the consumer repository.

Repo-specific needs

  • Settings of the standard jobs: pass env, pre-install-command, runs-on or timeout-minutes in ci.yml. Copier merges local edits with upstream changes, like a git merge. Extras for uv sync go through the uv_sync_args Copier answer.
  • Service containers: python-check.yml has no services: input. Start databases from the tests with testcontainers.
  • Extra jobs (migrations, OpenAPI, performance): add them to ci.yml with the same needs and if as pytest, and list them in the needs of tests-success, which only aggregates the jobs it names.

Required status checks

Require lint / check and Tests success. route / route, pytest / check and coverage / coverage are covered by the gate: declare them as optional jobs (route/route, pytest/check, coverage/coverage) in the organization's required-checks.json in github-config.