Compute the matrix at runtime
Sometimes the matrix can't be hardcoded — it depends on what changed in the PR, what packages exist in the monorepo, what tests are tagged, or what platforms a config file declares. Dynamic matrix computes the matrix in a setup job and feeds it to a downstream matrix job.
The pattern
- Setup job inspects the repo (changed files, package list, etc.).
- Emits a JSON array as a job output.
- Downstream matrix job sets
strategy.matrix.<key>: ${{ fromJSON(needs.setup.outputs.<key>) }}. - Each matrix cell runs the actual work.
Real examples
- Monorepo — only test packages whose code changed in this PR.
- Cross-platform builder — read
platforms.jsonfrom the repo and run a matrix cell per entry. - Tag-based — list of test groups marked in the test framework, expanded into matrix cells.