3. Tests and quality gates
3.1 T01 · Python runtime matrix with pip caching
GitHub Actions · Full workflow. Requires a committed requirements-dev.txt containing pytest and tests that support all listed versions. Pin requirements and their transitive dependencies for reproducible installs.
name: Python compatibility
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 3
matrix:
python: ['3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: requirements-dev.txt
- run: python -m pip install -r requirements-dev.txt
- run: python -m pytest -qVerify. Three jobs appear. Cause one version-specific failure in a scratch PR and check that the remaining variants can finish.
3.2 T02 · Ruff lint and format check
GitHub Actions or Gitea · Steps fragment. Requires an installed uv and a lockfile with Ruff in the dev group.
- name: Lint
run: uv run --locked ruff check .
- name: Check formatting
run: uv run --locked ruff format --check .Verify. Run uv run ruff format . locally to correct a formatting failure and compare the resulting diff.
3.3 T03 · Coverage threshold and test report
GitHub Actions · Steps fragment. Requires uv, pytest, pytest-cov and an importable package named calculator. Replace the package argument with your own. A failing test or sub-threshold coverage fails the test step. Diagnostic upload still runs unless the job was cancelled.
- name: Measure coverage
run: |
mkdir -p reports
uv run --locked python -m pytest \
--junitxml=reports/junit.xml \
--cov=calculator --cov-report=term-missing \
--cov-report=xml:reports/coverage.xml --cov-fail-under=80
- name: Retain test evidence
if: '!cancelled()'
uses: actions/upload-artifact@v4
with:
name: test-reports
path: reports/*.xml
if-no-files-found: warn
retention-days: 7Verify. Raise the threshold above the measured result. The job fails and still retains available reports. Avoid embedding secrets in test names, output or fixtures.
3.4 T04 · Postgres integration test
GitHub Actions · Full workflow. Requires a lockfile and a test at tests/integration/ that reads DATABASE_URL, applies your test schema and exercises a query. The credentials below belong to a disposable service isolated to the CI job.
name: Postgres integration
on: [push, pull_request]
permissions:
contents: read
jobs:
integration:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: ci
POSTGRES_PASSWORD: ci-only
POSTGRES_DB: ci
ports:
- 5432/tcp
options: >-
--health-cmd "pg_isready -U ci -d ci"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: astral-sh/setup-uv@v6
with:
enable-cache: false
- env:
DATABASE_URL: postgresql://ci:ci-only@127.0.0.1:${{ job.services.postgres.ports[5432] }}/ci
run: uv run --locked --python 3.12 python -m pytest -q tests/integration/Verify. The test proves the app can create or query its expected schema. A healthy service container alone only proves Postgres is accepting connections.
3.5 T05 · Node frontend checks
GitHub Actions · Full workflow. Requires package.json, package-lock.json and lint, test and build package scripts. Configure the test script for a single non-watch run.
name: Node verification
on: [push, pull_request]
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run buildVerify. Change package.json without updating the lockfile to observe npm ci rejecting the mismatch.
3.6 T06 · Always report the required PR check
GitHub Actions · Full workflow. Requires a root uv project with a default dev group containing pytest. This example runs tests on every PR and whenever the merge queue creates a merge_group, if enabled.
name: Required verification
on:
pull_request:
branches: [main]
merge_group:
permissions:
contents: read
jobs:
required-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: astral-sh/setup-uv@v6
with:
enable-cache: false
- run: uv run --locked --python 3.12 python -m pytest -qVerify. Run this on a PR before choosing its exact reported status check in a rule. Compare a file-filtered workflow and the required workflow on a README-only change.
3.7 T07 · Terraform static validation
Linux · Script fragment. Requires Terraform on PATH and a root module at infra/. This example can download providers and modules during initialization. It runs without remote state initialization.
set -euo pipefail
terraform -chdir=infra fmt -check -recursive
terraform -chdir=infra init -backend=false -input=false
terraform -chdir=infra validate -no-colorVerify. Introduce an invalid attribute and check that validation fails. An actual plan against cloud state needs a separately authorized and isolated environment.
Reference · GitHub service containers, workflow events, Terraform validate.