bashintermediate
GitHub Actions Test Matrix Strategy
GitHub Actions workflow with matrix strategy to test across multiple Node versions and OS platforms.
bashPress ⌘/Ctrl + Shift + C to copy
# .github/workflows/test-matrix.yml
name: Test Matrix
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [18, 20, 22]
exclude:
- os: windows-latest
node-version: 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm test
- name: Upload coverage
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 20
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npx tsc --noEmitUse Cases
- Cross-platform compatibility testing
- Testing across multiple runtime versions
- Comprehensive CI validation for libraries
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
yamladvanced
GitHub Actions — Advanced Matrix Strategy
Complex matrix strategies with include/exclude, fail-fast control, and dynamic matrix generation.
Best for: Cross-platform and multi-version testing
#github-actions#matrix
bashintermediate
GitHub Actions CI/CD Pipeline
Complete GitHub Actions workflow with test, build, and deploy stages for a Node.js application.
Best for: Automated testing and deployment on push
#github-actions#ci-cd
bashintermediate
GitHub Actions Docker Build and Push
GitHub Actions workflow to build a Docker image and push it to GitHub Container Registry on release.
Best for: Automated Docker image publishing on release
#github-actions#docker
yamlbeginner
GitHub Actions — Node.js CI Pipeline
Complete CI workflow for Node.js: install, lint, test, build on every push and PR with caching.
Best for: Automated testing on every push and PR
#github-actions#ci-cd