CI Matrix Math: Counting the Jobs Behind Every Push

A test matrix looks cheap in YAML: three lines of runtime versions, a line of operating systems, and suddenly every pull request fans out into dozens of jobs. This page gives you the arithmetic to see that number before you commit it, plus a worked example you can redo with your own values on paper or in a spreadsheet.

The formula

A matrix multiplies its axes. If you test on R runtime versions, O operating systems and V variants of a key dependency (say, two major versions of a peer dependency), the job count is:

jobs_per_run   = R × O × V  − excluded_combinations + included_extras
minutes_per_run = Σ (job_duration × os_multiplier)
monthly_minutes = minutes_per_run × runs_per_month

The os_multiplier matters because many hosted CI providers bill or throttle macOS and Windows runners differently from Linux ones. Check your provider's own pricing or quota page for the current ratios rather than trusting a figure from a blog post, including this one; we deliberately do not quote numbers here because they change.

A worked example (illustrative)

Package A is a small parsing library. Its maintainer wants to cover three supported Node.js lines, three operating systems and two major versions of an optional peer dependency.

InputAssumed value
Runtime versions (R)3
Operating systems (O)3 (Linux, macOS, Windows)
Peer dependency majors (V)2
Average job duration4 minutes
Pushes and PR updates per month120

Raw job count is 3 × 3 × 2 = 18 jobs per run. At four minutes each that is 72 runner-minutes per push before any OS weighting, and 8,640 minutes a month at 120 runs. These are assumed inputs, not measurements; your durations will differ, and cold caches on new runners often push the first job of the day well above the average.

Where to cut without losing coverage

Most of those 18 jobs are not telling you anything new. Bugs that depend on the operating system are usually about file paths, line endings or native builds, and they rarely interact with the peer dependency version. That suggests a sparse matrix:

In GitHub Actions you express this with include and exclude entries under strategy.matrix; other CI systems have equivalents. Another lever is splitting triggers: run the sparse matrix on every pull request and the full one on a nightly schedule or before tagging a release.

Limits of this calculation

The math counts jobs and minutes; it does not tell you which combinations your users actually run. If you have no data, the runtime's own release schedule is a reasonable proxy: test every line that is still in active or maintenance support and drop the ones that have reached end of life. Queue time is also missing from the formula. A matrix of 18 jobs on a free tier with limited concurrency can take far longer in wall-clock time than its minute count suggests, which slows reviews more than it costs money.

For what to put in each job, see the notes on choosing a package test matrix, and for the step that runs after the matrix passes, the guide to testing the packed tarball before publishing.