GitHub Actions: Jobs, Steps, Matrix, and Reusable Building Blocks/Test across multiple Node versions
Use a strategy matrix for version coverage.
Section: Matrix, reuse, and services
Test across multiple Node versions
yaml
yaml
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm testExplanation
Matrix builds are the standard way to validate against multiple versions or OSes.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Matrix, reuse, and services
Run on multiple operating systems
Validate portability across Linux, macOS, and Windows.
Start a PostgreSQL service container
Run integration tests against a database service.
Call a reusable workflow
Centralize shared CI logic in one workflow file.
Composite action metadata
Bundle repeated shell steps into a reusable local action.