AI Hints
Home›CI/CD with GitHub Actions Tutorial›Concurrency and Practice
CI/CD with GitHub Actions · Lesson 57 of 138

Practice: A Matrix Pipeline

Your turn.

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

Practice time. Write a CI workflow that tests on Ubuntu and Mac OS, with Python three point eleven and three point twelve. Every result should be shown, even if one fails. Pause, and write it.

Practice: A Matrix Pipeline
From the video: Practice: A Matrix Pipeline
  • Two systems
  • Two Python versions
  • Show every result

One answer

The matrix lists two systems and two versions, four jobs. Runs on reads matrix dot o s, so each job gets the right machine. Setup python reads matrix dot python. And fail fast false shows every result. The steps are the same for all four jobs.

.github/workflows/ci.ymlyaml
name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        python: ["3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}
      - run: pip install -q -r requirements.txt
      - run: pytest -q

Checking it

Actionlint finds no problems, so it prints nothing. And our helper shows the four combinations it would run. On GitHub, two would run on Ubuntu runners, and two on Mac OS runners, all at once.

Terminal
actionlint && echo "no problems"
no problems
run-steps .github/workflows/ci.yml | grep -E "^Job"
Job: test (ubuntu-latest, 3.11)
Job: test (ubuntu-latest, 3.12)
Job: test (macos-latest, 3.11)
Job: test (macos-latest, 3.12)

Summary

Matrix values can choose the runner and the Python version. Fail fast false shows every result. Next, a pipeline where testing waits for building.

Key takeaways
  • runs-on: ${{ matrix.os }}
  • python-version from matrix
  • fail-fast: false
Next up: Practice: Build Then Test — jobs with artifacts