Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
name: test
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, windows-2022]
python: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install -r requirements-dev.txt
- run: pytest -q2 OS × 3 Python versions = 6 jobs in parallel.
Step by step
- Define the axes under
strategy.matrixand use them as${{ matrix.NAME }}(quick answer). - **
fail-fast: false** — otherwise the first failure cancels the other jobs and you do not see the full picture. - Add or remove single combinations:
matrix:
os: [ubuntu-24.04, windows-2022]
python: ["3.11", "3.12", "3.13"]
exclude:
- os: windows-2022
python: "3.11"
include:
- os: ubuntu-24.04
python: "3.14"
experimental: trueWith continue-on-error: ${{ matrix.experimental == true }} on the job, a new version may fail without blocking.
- A database version matrix with a service container:
strategy:
matrix:
pg: ["16", "17"]
services:
postgres:
image: postgres:${{ matrix.pg }}
env: { POSTGRES_PASSWORD: test }
ports: ["5432:5432"]
options: --health-cmd "pg_isready" --health-interval 5s --health-retries 10- Required checks: each matrix job has its own name (
test (ubuntu-24.04, 3.12)). Simplest: add one small job thatneeds: testand mark that job as required:
all-tests:
needs: test
runs-on: ubuntu-24.04
steps:
- run: echo "all matrix jobs passed"- Limit cost:
max-parallel: 4; run the full matrix onmainand nightly, a smaller one on pull requests.
Check that it worked
The Actions run shows one job per combination with its name, a failure in one combination does not cancel the others, and the all-tests job is green only when all are green.
Common problems
| Problem | Cause | Fix |
|---|---|---|
3.10 becomes 3.1 | YAML reads it as a number. | Quote versions: "3.10". |
| One failure cancels everything | fail-fast is true by default. | fail-fast: false. |
| Required check never matches | Matrix job names contain the values. | Require a summary job with needs:. |
| Too many jobs / minutes | Large matrix on every push. | Smaller matrix on PRs; full matrix nightly; max-parallel. |
| Windows job fails on shell commands | Default shell is PowerShell. | shell: bash on the step, or OS-specific steps with if: runner.os == 'Windows'. |
include adds a whole new job unexpectedly | include keys that do not match an existing combination add one. | Match existing values to extend; otherwise it is a new job (as intended). |
Go further
- Command pages: gh.
- Next how-tos: Create a CI pipeline in GitHub Actions, Cache dependencies in CI, Build and push an image in CI.
- Learn it: GitHub Actions — Matrix, Reusable workflows, Service containers, Required checks.
1What does fail-fast: false change?
A failing matrix job no longer cancels the other jobs, so you see all results.
2How do you make a matrix a single required status check?
Add a job that needs: the matrix job and mark that job as required.