GitHub Actions — Advanced Matrix Strategy
Complex matrix strategies with include/exclude, fail-fast control, and dynamic matrix generation.
name: Advanced Matrix CI
on: [push, pull_request]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [18, 20, 22]
exclude:
- os: macos-latest
node: 18
- os: windows-latest
node: 18
include:
- os: ubuntu-latest
node: 22
experimental: true
coverage: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm test
- name: Upload coverage
if: matrix.coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.os }}-${{ matrix.node }}
path: coverage/
continue-on-error: ${{ matrix.experimental == true }}
# Dynamic matrix from a script
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: |
echo "matrix=$(ls packages/*/package.json | \
jq -R -s '{package: split("\n") | map(select(. != "")) }')" \
>> $GITHUB_OUTPUTSponsored
GitHub
Use Cases
- Cross-platform and multi-version testing
- Dynamic CI matrices from project structure
- Selective platform testing with exclude rules
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
GitHub Actions Test Matrix Strategy
GitHub Actions workflow with matrix strategy to test across multiple Node versions and OS platforms.
Best for: Cross-platform compatibility testing
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 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 — 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