Skip to content

Lesson 2 of 9 · 22m

Matrix Strategies Without Combinatorial Explosion

Use matrices to test meaningful variation while controlling cost, runtime, and confusing failure ownership.

A matrix job is a force multiplier, which means it multiplies good design and bad judgment with equal enthusiasm. I have seen three operating systems, four language versions, and five database versions become sixty jobs because someone wrote the Cartesian product first and asked what risk it represented never. Matrices should encode compatibility risk, not decorate a dashboard.

Start with the compatibility contract

Write down what you actually support:

Node.js:   active LTS versions 20 and 22
Postgres:  15 and 16
Browsers:  Chromium current, Firefox current
OS:        Ubuntu 24.04 for production containers

That list is not necessarily a matrix. If production runs only Linux, macOS unit tests may catch developer-environment issues but are not release evidence. Separate informational coverage from blocking release criteria.

Use include and exclude deliberately

GitHub Actions multiplies every axis by default:

strategy:
  fail-fast: false
  matrix:
    node: ["20", "22"]
    postgres: ["15", "16"]
    include:
      - node: "22"
        postgres: "17"
        experimental: true
    exclude:
      - node: "20"
        postgres: "16"

include adds targeted combinations; exclude removes combinations you do not support. Prefer a small explicit list when the important combinations are irregular.

Control blast radius

fail-fast: true cancels sibling jobs after one failure. That saves minutes but destroys information: you no longer know whether the failure is isolated to Node 20 or universal. Use fail-fast: false for compatibility matrices and reserve fast cancellation for expensive smoke jobs where cost dominates.

Concurrency controls matter too:

concurrency:
  group: matrix-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

Cancelling stale pull-request runs is usually correct. Cancelling release validation is usually not.

Shard tests inside one matrix leg

Do not create matrix dimensions for test files. Use test sharding when runtime is the problem:

npx playwright test --shard="${{ strategy.job-index }}/4"

Matrix dimensions model environmental differences. Shards divide otherwise equivalent work. Confusing those two concepts produces unreadable failures and runner bills nobody can defend.

Make failures legible

Job names should carry the dimensions: integration (node 22, postgres 16). Emit the exact versions in logs because latest is a moving target. Upload one report per combination, using names that cannot collide. A matrix failure without a stable artifact link becomes archaeology.

Field notes

  • continue-on-error belongs on clearly labeled experimental legs, not quietly on the whole matrix.
  • Matrix expansion happens before most conditional expressions; verify whether skipped legs still consume queue time.
  • Keep the blocking pull-request matrix small. Push exhaustive compatibility sweeps to nightly builds.
  • A dimension that has never failed in a year is either valuable insurance or noise; measure it instead of guessing.

Was this lesson helpful?

Sign in to rate