AI Hints
Home›CI/CD with GitHub Actions Tutorial›Matrix Options and Caching
CI/CD with GitHub Actions · Lesson 49 of 138

Matrix include and exclude

Fine-tuning combinations.

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

Sometimes the full grid of combinations isn't quite right. One combination might be unsupported, or you might want to add one special extra case. Exclude removes combinations, and include adds them.

Matrix include and exclude
From the video: Matrix include and exclude
  • The full grid isn't always right
  • Remove some
  • Add some

Exclude and include

The grid starts with two versions on two systems, four jobs. Exclude removes Python three point eleven on Windows, leaving three. Include adds one extra job, Python three point thirteen on Ubuntu. So the final matrix has four jobs, but not the same four.

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

The final list

Here are the jobs the matrix produced. Three point eleven runs only on Ubuntu. Three point twelve runs on both. And the extra three point thirteen job appears at the end. Exactly what we described.

Terminal
run-steps .github/workflows/matrix.yml | grep -E "^Job"
Job: test (3.11, ubuntu-latest)
Job: test (3.12, ubuntu-latest)
Job: test (3.12, windows-latest)
Job: test (3.13, ubuntu-latest)

Summary

Exclude removes combinations from the grid, and include adds extra ones. Next, what happens when one matrix job fails.

Key takeaways
  • exclude: remove
  • include: add
  • Check the job list
Next up: fail-fast — stop early, or see everything