AI Hints
Home›CI/CD with GitHub Actions Tutorial›Conditions and Matrices
CI/CD with GitHub Actions · Lesson 48 of 138

Matrix Builds

Many versions at once.

⏱ 2 min read▶ Video at 54:32🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Your users might run different Python versions, on different operating systems. Testing every combination by hand would be painful. A matrix creates one job for every combination, automatically.

Matrix Builds
From the video: Matrix Builds
  • Many versions
  • Many systems
  • One job per combination

A matrix

Under strategy, matrix lists the values to combine. Three Python versions, and two operating systems. That's three times two, six jobs. Each job reads its own values with matrix dot python, and matrix dot o s. Usually you'd pass matrix dot o s to runs on, and the version to setup python.

.github/workflows/matrix.ymlyaml
name: Matrix
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python: ["3.11", "3.12", "3.13"]
        os: [ubuntu-latest, windows-latest]
    steps:
      - run: echo "Testing Python ${{ matrix.python }} on ${{ matrix.os }}"

Six jobs

Our helper runs one job for each combination, and prints its values. On GitHub, all six would run in parallel, on real Ubuntu and Windows machines. The run page shows each combination as its own job.

Terminal
run-steps .github/workflows/matrix.yml | grep -E "^ +Testing"
      Testing Python 3.11 on ubuntu-latest
      Testing Python 3.11 on windows-latest
      Testing Python 3.12 on ubuntu-latest
      Testing Python 3.12 on windows-latest
      Testing Python 3.13 on ubuntu-latest
      Testing Python 3.13 on windows-latest

Summary

A matrix makes one job for every combination of its values, and they run in parallel. Next, adding and removing combinations.

Key takeaways
  • strategy: matrix:
  • 3 × 2 = 6 jobs
  • ${{ matrix.python }}
Next up: Matrix include and exclude — fine-tuning combinations