๐ค AI Prompt โ stuck? paste this
โAdd a build matrix so my tests run on Node.js 18, 20, and 22 in parallel. Explain how matrix and ${{ matrix.node }} work.โ
03 โ Test across multiple versions with a build matrix
Category: Workflows ยท Priority: Medium ยท Step: 4
Run the same job against several Node.js versions in parallel using a
matrix.
๐ฏ What is this task?
Your app might run on Node 18 in one place and Node 20 in another. A matrix lets one job fan out into several parallel runs โ one per version โ so you catch "works on my machine" bugs early. GitHub runs them simultaneously and shows each as its own check.
๐ค AI Prompt
"Add a build matrix to my GitHub Actions job so my tests run on Node.js 18, 20, and 22 in parallel. Explain how
matrixand${{ matrix.node }}work."
๐ Step-by-step
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ["18", "20", "22"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "npm"
- run: npm ci
- run: npm test
matrix.nodeexpands into three runs.${{ matrix.node }}is the current value for each run.fail-fast: falselets the other versions finish even if one fails, so you see the full picture.
โ Done when
- The Actions tab shows three parallel
testchecks - Each uses a different Node.js version
- You understand what
${{ matrix.node }}resolves to
๐ Quiz
Answer all 2 questions correctly to complete this lesson.
1. What does a build matrix let you do?
2. What does `fail-fast: false` change?