GitHub Actions Workflow Template for Monorepo (matrix)
A complete, caching-enabled GitHub Actions workflow for Monorepo (matrix). Drop it in .github/workflows/ci.yml and adjust.
This template builds and tests a Monorepo (matrix) project with dependency caching and sensible defaults. It runs a matrix across packages so only what changed is built (wire your own change detection).
The workflow
.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: [api, web, worker]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm test --workspace ${{ matrix.package }}What it does
- Runs a job per package in parallel
- Pattern for affected-only builds
Run it cheaper
Change runs-on: ubuntu-latest to a Latchkey label to run this same 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…
CI/CD for Monorepos: Build Only What ChangedCI/CD for monorepos - affected-only builds, matrix sharding, caching, and controlling cost as the repo and te…
How to Speed Up GitHub Actions: 9 High-Impact TacticsMake GitHub Actions faster: caching, parallelization, test splitting, Docker layer caching, slimmer images, a…