Skip to content
Visual explainer 2h to learn 3 steps

Runners & matrix builds

Test across versions and operating systems in parallel.

By Invicly Tech, , in Git, GitHub & GitHub Actions. About 10 minutes to read.

Topic 10 of 18

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.

CompareRunner types
GitHub-hosted
  • Fresh VM every job
  • Ubuntu, Windows, macOS
  • No maintenance
  • Billed by minutes on private repos
Self-hosted
  • Your machine or cluster
  • Custom hardware or network access
  • You patch and secure it
  • Avoid for public repos
Mapmatrix: os x python = 4 jobs
test job
  • ubuntu-latest
    • python 3.11
    • python 3.12
  • windows-latest
    • python 3.11
    • python 3.12
CompareChoosing where jobs run
Standard hosted
  • Zero setup
  • Clean VM every job
  • Linux, Windows, macOS
  • Free for public repos
Larger hosted
  • More CPU, RAM or a GPU
  • Still managed by GitHub
  • Paid per minute
  • Good for heavy builds
Self-hosted
  • 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.

SequenceAn ephemeral self-hosted runner
Runner agent
GitHub
Workflow job
  1. 1Register with labels (config.sh --ephemeral)
    Runner agent to GitHub: Register with labels (config.sh --ephemeral)
  2. 2Long-poll over HTTPS: any work?
    Runner agent to GitHub: Long-poll over HTTPS: any work?
  3. 3Job matching [self-hosted, linux, gpu]
    GitHub to Runner agent: Job matching [self-hosted, linux, gpu]
  4. 4Run steps on this machine
    Runner agent to Workflow job: Run steps on this machine
  5. 5Upload logs and result
    Runner agent to GitHub: Upload logs and result
  6. 6Unregister; machine is recycled
    Runner agent to GitHub: Unregister; 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.

FlowExpanding a matrix
  1. 1
    Cross product

    Every value of every list

  2. 2
    Apply exclude

    Remove matching combinations

  3. 3
    Apply include

    Add keys, or add new combinations

  4. 4
    Schedule jobs

    Up to max-parallel at once

  5. 5
    Report 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.

  1. 1
    Compare GitHub-hosted and self-hosted runners~40m
  2. 2
    Add a matrix of versions and OSes~40m
  3. 3
    Use 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

yaml
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 pytest

Three 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.

yaml
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.

yaml
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 }}" test

Quick 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.

Question 1

1Matrix: os has 2 values, node has 3 values, and one exclude entry matches one combination. How many jobs run?

Question 2

2An include entry adds a key that matches no existing combination without overwriting a value. What happens?

Question 3

3Why is a non-ephemeral self-hosted runner risky?

Question 4

4One combination fails and the other matrix jobs are cancelled. Which setting caused that?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Run your tests on Node 20, 22 and 24 on Linux with a matrix.

  2. 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.

  3. 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.

Go deeper

ShareXLinkedInWhatsApp