Runners & matrix builds
Test across versions and operating systems in parallel.
By Invicly Tech, , in Git, GitHub & GitHub Actions. About 10 minutes to read.
In short
Runners are the machines that execute jobs, either hosted by GitHub or run by you. A matrix fans one job out into many parallel copies, such as every Python version on every OS.
Explained simply
A runner is the computer that runs your job. GitHub-hosted runners are virtual machines that GitHub starts for you: Linux, Windows or macOS, with many tools already installed. Self-hosted runners are machines you own and connect to GitHub, such as a server in your data centre or a box with a GPU.
A matrix is a shortcut for testing many setups. Instead of writing one job for Python 3.12 on Linux, another for 3.13 on Linux, and so on, you list the values once. GitHub creates every combination and runs them all at the same time.
Why bother? Your users run different versions and operating systems. A bug that only appears on Windows, or only on the newest Node version, is cheap to catch in CI and expensive to catch in production.
Matrices also need control. You can leave out combinations that do not make sense (exclude), add special ones (include), and decide whether one failure should cancel the rest (fail-fast). Each combination costs runner minutes, so test what matters, not everything.
Press Play on a diagram to walk through it one step at a time.
- Fresh VM every job
- Ubuntu, Windows, macOS
- No maintenance
- Billed by minutes on private repos
- Your machine or cluster
- Custom hardware or network access
- You patch and secure it
- Avoid for public repos
- ubuntu-latest
- python 3.11
- python 3.12
- windows-latest
- python 3.11
- python 3.12
- Zero setup
- Clean VM every job
- Linux, Windows, macOS
- Free for public repos
- More CPU, RAM or a GPU
- Still managed by GitHub
- Paid per minute
- Good for heavy builds
- Your hardware and network
- Reach private services
- You patch and secure it
- Use ephemeral runners
In depth
GitHub-hosted runners in practice
Each job gets a brand-new virtual machine that is destroyed afterwards. Common labels are ubuntu-latest (currently Ubuntu 24.04), ubuntu-24.04-arm for ARM64, windows-latest and macos-latest. The -latest labels move to new OS versions over time, so pin a version like ubuntu-24.04 if a change in the image would break you. The installed software for each image is listed in the actions/runner-images repository.
Public repositories use standard runners for free. Private repositories spend included minutes, and Windows and macOS minutes cost more than Linux minutes, so run most of your matrix on Linux. Larger runners with more CPU, more memory or GPUs are available on paid plans.
- runner.os is Linux, Windows or macOS inside a job
- Pin ubuntu-24.04 instead of ubuntu-latest for reproducible builds
- Hosted runners give you passwordless sudo, and Docker on Linux images
How self-hosted runners connect
A self-hosted runner is a small agent program you install from Settings, Actions, Runners. ./config.sh registers it with a short-lived token, and ./run.sh (or ./svc.sh install for a service) starts it. The runner opens an outbound HTTPS connection and long-polls GitHub for work, so you do not need to open any inbound ports.
Runners get default labels such as self-hosted, linux and x64, plus custom ones like gpu. runs-on: [self-hosted, linux, gpu] picks a runner that has all of those labels. A normal self-hosted runner keeps its disk between jobs, which can leak files or secrets from one job to the next. Use --ephemeral so it takes one job and then unregisters, or run autoscaling ephemeral runners on Kubernetes with Actions Runner Controller.
- Runner agent to GitHub: Register with labels (config.sh --ephemeral)1Register with labels (config.sh --ephemeral)
- Runner agent to GitHub: Long-poll over HTTPS: any work?2Long-poll over HTTPS: any work?
- GitHub to Runner agent: Job matching [self-hosted, linux, gpu]3Job matching [self-hosted, linux, gpu]
- Runner agent to Workflow job: Run steps on this machine4Run steps on this machine
- Runner agent to GitHub: Upload logs and result5Upload logs and result
- Runner agent to GitHub: Unregister; machine is recycled6Unregister; machine is recycled
How include and exclude really work
GitHub first builds every combination of the matrix lists, then removes the ones that match an exclude entry, then processes include. For each include entry, GitHub tries to add its keys to existing combinations, but only where doing so would not overwrite any original matrix value. If the entry fits nowhere, it becomes a new combination of its own.
So include: [{ python: "3.13", coverage: true }] adds coverage: true to every combination that already has python 3.13. include: [{ os: macos-latest, python: "3.13" }] with no macOS in the matrix creates one extra job. A single matrix can generate at most 256 jobs per workflow run.
- 1Cross product
Every value of every list
- 2Apply exclude
Remove matching combinations
- 3Apply include
Add keys, or add new combinations
- 4Schedule jobs
Up to max-parallel at once
- 5Report checks
One check per combination
fail-fast, max-parallel and dynamic matrices
fail-fast is true by default: when one matrix job fails, GitHub cancels the ones still running. That saves minutes but hides whether the failure is everywhere or only on one OS, so many teams set fail-fast: false. max-parallel limits how many matrix jobs run at once, useful when tests hit a shared test server. continue-on-error: true on a job lets a combination fail without failing the run, perfect for a pre-release version you only want to watch.
The matrix does not have to be written by hand. A first job can output a JSON array and the matrix can read it with fromJSON(needs.plan.outputs.list). This is how monorepos test only the packages that changed. Guard against an empty list, because an empty matrix makes the job fail.
Learn it in 3 short steps
About 40m each. Track them with a timer in your plan.
- 1Compare GitHub-hosted and self-hosted runners~40m
- 2Add a matrix of versions and OSes~40m
- 3Use include, exclude and fail-fast~40m
Key points
- Each matrix combination is its own job running in parallel.
- include adds extra combinations or variables; exclude removes specific ones.
- fail-fast: true cancels the rest when one combination fails; set false to see all.
- Self-hosted runners on public repos can run untrusted code from forks.
Key terms
Tap a card to flip it. 0/5 known
Examples
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: ["3.11", "3.12"]
exclude:
- { os: windows-latest, python: "3.11" }
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: "${{ matrix.python }}" }
- run: python -m pytestThree combinations after the exclude, all reported even if one fails.
A focused matrix with one extra job
You support Python 3.12 and 3.13 on Linux, want coverage measured once, and want to watch macOS without blocking merges. Step 1: list python versions and one OS. Step 2: an include entry adds coverage: true to the 3.13 job. Step 3: another include entry creates a new macOS job marked experimental. Step 4: continue-on-error reads that flag, and fail-fast is off so every result is visible. Result: three jobs.
jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
python: ["3.12", "3.13"]
os: [ubuntu-latest]
include:
- { python: "3.13", coverage: true }
- { python: "3.13", os: macos-latest, experimental: true }
steps:
- uses: actions/checkout@v4
- run: echo "py=${{ matrix.python }} cov=${{ matrix.coverage }}"A dynamic matrix for a monorepo
Your repo has a services/ folder with one subfolder per service. Step 1: a plan job lists the folders and turns them into a JSON array with jq. Step 2: it exposes the array as a job output. Step 3: the test job builds its matrix with fromJSON, so adding a new service folder adds a new test job with no YAML change.
jobs:
plan:
runs-on: ubuntu-latest
outputs: { services: "${{ steps.ls.outputs.services }}" }
steps:
- uses: actions/checkout@v4
- id: ls
run: echo "services=$(ls services | jq -R . | jq -s -c .)" >> "$GITHUB_OUTPUT"
test:
needs: plan
runs-on: ubuntu-latest
strategy: { matrix: { service: "${{ fromJSON(needs.plan.outputs.services) }}" } }
steps:
- uses: actions/checkout@v4
- run: make -C "services/${{ matrix.service }}" testQuick reference
- ubuntu-latest is Ubuntu 24.04; pin ubuntu-24.04 for stable builds
- Quote versions in YAML: "3.10" stays a string, 3.10 becomes 3.1
- fail-fast is true by default; set false to see every failing combination
- max-parallel: 2 limits how many matrix jobs run at once
- A matrix can create at most 256 jobs per workflow run
- runs-on: [self-hosted, linux, gpu] needs a runner with all those labels
- config.sh --ephemeral makes a self-hosted runner take exactly one job
- fromJSON(needs.plan.outputs.list) builds a matrix from a previous job
Common mistakes
- Writing 3.10 unquoted in YAML, which becomes the number 3.1.
- A huge matrix that burns minutes when a few combinations would do.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Run your tests on Node 20, 22 and 24 on Linux with a matrix.
- Exercise 2medium
Test on Linux and Windows with Python 3.12 and 3.13, but skip Windows with 3.12, and make sure all results are reported even if one fails.
- Exercise 3hard
Make the matrix job names readable in the PR checks list and protect against an empty dynamic matrix.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How many jobs can run at the same time?
- It depends on your plan's concurrency limit for hosted runners, and on how many self-hosted runners you have. Within one matrix you can lower it further with max-parallel.
- Should I use self-hosted runners for a public repo?
- Generally no. Anyone can open a pull request, and a fork's workflow code could run on your machine. Use GitHub-hosted runners, or tightly controlled ephemeral runners with approval for outside contributors.
- How do I see what software is installed on ubuntu-latest?
- Open the Set up job step in any run log; it links to the image version. The full list is in the actions/runner-images repository on GitHub.