GitHub Actions Workflow for Matrix Across Node Versions
Test against several Node.js versions at once.
This workflow fans out a matrix across Node LTS versions so you catch version-specific failures before release.
The workflow
.github/workflows/ci.yml
name: CI
on: [push, pull_request]
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 testNotes
- Matrix runs install and test once per Node version.
fail-fast: falselets every version report so you see all failures.- Add
osto the matrix to also span platforms.
Run it cheaper
Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.
Related guides
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
GitHub Actions Workflow Template for Node.jsA ready-to-use GitHub Actions workflow for Node.js with caching and best practices - copy, commit, and run fa…
How to Speed Up GitHub Actions: 9 High-Impact TacticsMake GitHub Actions faster: caching, parallelization, test splitting, Docker layer caching, slimmer images, a…