Managing GitHub Actions Matrix Growth and Cache Behavior
Matrix strategies auto-generate job dimensions, but without explicit dependency and cache controls, individual failures can cascade and caching stops working. This post walks through a practical workflow configuration and verification steps.
04 Sept 2026, 00:56 UTC

Problem: Matrix combinatorics escape the gate
In a recent CI overrun, a matrix defined with strategy.matrix across two OS families and three Node versions generated 10 jobs instead of the expected 6, and the actions/cache step stopped sharing the ~/.npm directory across dimensions. The workflow failed at the first dimension that lacked a cached artifact, and because of the default run error behavior, subsequent dimensions never started.
Thesis
The declarative matrix syntax in GitHub Actions has been stable since 2020, supporting nested matrices, exclude refinements, and runtime expressions for dynamic job generation without custom scripting. However, three practical controls—explicit dimension pruning, dependency declaration, and UI‑driven debugging—keep combinatorics from blowing up your CI budget.
Declaring dimensions with strategy.matrix
At its core, strategy.matrix produces the Cartesian product of every listed dimension. A minimal workflow that builds on Ubuntu and Windows with Node 18 and 18 yields four jobs:
name: 'Matrix demo'
on: push
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
Adding jobs.build.strategy.matrix.include lets you inject a single custom dimension without expanding every combination, which is the first lever for controlling job count.
Cache and artifact interactions in matrix jobs
The actions/cache step relies on the key you provide. If the key omits matrix variables, the cache becomes a single shared bucket that may miss or conflict across dimensions. The following configuration ties the cache key to both the runner OS and the Node version:
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }>
When a dimension fails, the default error propagation stops the entire workflow. Appending continue-on-error: true to the step or job lets other dimensions proceed, which is useful for non‑critical tests but requires careful log review.
Debugging via the Actions UI
The Actions interface visualizes the matrix expansion, showing per‑dimension status, duration, and logs. You can collapse individual rows to inspect failures without re‑triggering the whole workflow, and the UI reports the exact Cartesian product that was generated.
Trade‑off and limitation
Matrix dimension combinatorics can produce exponential job growth quickly exceeding workflow timeout limits and inflating CI costs on paid runners. Secrets and environment variables declared at the workflow level are not automatically propagated to each matrix dimension; each dimension requires explicit re‑declaration or sharing via needs outputs.
Actionable checklist
- Verify the expected job count in the Actions UI after defining
matrix. - Use
includeonly when a single custom dimension is needed; avoid nested matrices deeper than two levels. - Add matrix variables to
actions/cachekeys so each dimension gets its own cache entry. - Add
continue-on-error: trueselectively if a failing dimension should not block the rest. - Declare secrets at the job level or use
needsoutputs to share them across dimensions.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.