GitHub Actions for Monorepos: Fast CI Without Pipeline Chaos
A docs-only PR that waits behind three unrelated backend changes for 35 minutes is not a caching problem. It is a missing ownership boundary.
Key takeaways
- Fast monorepo CI on GitHub Actions comes from running less, not from bigger runners.
- Detect which paths changed, feed only the affected services into a matrix, and gate deploys on main pushes with protected environments.
- Make shared packages trigger every dependent service, and watch for path-filtered workflows leaving required checks pending.
On this page
To make monorepo CI fast on GitHub Actions, stop running every job on every pull request. Add a change-detection job (dorny/paths-filter or a git diff), build a matrix from only the services that changed, and gate deploys on pushes to main behind protected environments. A bigger runner does not fix work that never needed to run.
Verified against
actions/checkout v7.0.1, actions/setup-node v7.1.0, dorny/paths-filter v4.0.3, against the GitHub Actions workflow syntax, reusable workflows and deployment environments docs. Checked October 2026.
The failure usually looks the same. A repo grows from a handful of services to a few dozen deployable apps, and the pipeline never changes shape to match. Every pull request triggers the same matrix of tests, Docker builds, lint jobs and preview environments, so a docs-only PR waits behind unrelated backend changes and still burns half an hour of CI. People start batching risky changes together just to avoid the wait, which makes review harder at exactly the size where rollouts need to get safer.
Monorepos are good for shared ownership and cross-service refactoring. The tax is that CI gets slow and expensive fast when every job runs regardless of what it touches. The fix is a build contract: targeted execution, predictable caching, and deploy gates that only apply to what changed.
The three-layer pattern
Every workflow that scales past a handful of services ends up with the same shape: change detection decides what was touched, a targeted matrix runs only the affected jobs, and a protected deploy stage runs only from trusted branches and environments. Skipping the first layer is the mistake that costs the most, because it is the one that makes the other two irrelevant. A perfectly cached build job is still wasted work if nothing needed to run.
Detect what actually changed
# .github/workflows/ci.yml
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
detect:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.set.outputs.services }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # the default shallow clone has no origin/main to diff against
- id: set
run: |
CHANGED=$(git diff --name-only origin/main...HEAD | cut -d/ -f1,2 | sort -u)
SERVICES=$(echo "$CHANGED" | grep '^services/' | cut -d/ -f2 | jq -R -s -c 'split("\n")[:-1]')
echo "services=$SERVICES" >> $GITHUB_OUTPUT
This keeps a change to docs or an unrelated folder from building applications that were never touched. dorny/paths-filter is the more maintainable version of the same idea once you have more than a handful of services, since it lets you declare each service's dependency footprint explicitly instead of parsing diffs by hand:
# .github/workflows/ci.yml (paths-filter variant)
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
api_changed: ${{ steps.filter.outputs.api }}
web_changed: ${{ steps.filter.outputs.web }}
steps:
- uses: actions/checkout@v7
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
api:
- "apps/api/**"
- "packages/shared/**"
web:
- "apps/web/**"
- "packages/shared/**"
api_checks:
needs: detect_changes
if: needs.detect_changes.outputs.api_changed == 'true'
uses: ./.github/workflows/service-checks.yml
with:
service_path: apps/api
The shared-package pattern matters more than it looks: a change to packages/shared should trigger every service that depends on it, not just the folder that literally changed. Missing this is how a "fast" pipeline quietly stops testing things that actually broke.
Run only the affected matrix
# .github/workflows/ci.yml (continued)
test:
needs: detect
if: ${{ needs.detect.outputs.services != '[]' }}
strategy:
matrix:
service: ${{ fromJson(needs.detect.outputs.services) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npm run lint --workspace=services/${{ matrix.service }}
- run: npm run test --workspace=services/${{ matrix.service }}
Fail fast here matters as much as the targeting does. Lint and type checks should block before the heavier integration suite starts, not run in parallel with it, so a trivial mistake gets reported in seconds instead of after a ten-minute build.
Gate the deploy, not just the build
# .github/workflows/ci.yml (deploy job condition)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
Pair this with a protected production environment that has required reviewers, so a human approves the deploy. Our guide to reusable workflows at org scale covers how to share the service-checks workflow across repos. This is also where reusable workflows earn their keep: keeping each service's checks in a small, explicit workflow file means new engineers, auditors, and on-call responders can read exactly what a given service's pipeline owns without reconstructing it from a 400-line monolith.
What actually moved the number
Larger runners are usually the first thing teams try, and they barely help, because the problem was never raw compute. What works is reworking the pipeline around dependency-aware paths, splitting fast confidence checks (lint, type checks, unit tests) from slower service-specific builds, and tracking queue time and cache hit rate rather than just total workflow duration. Watching only total duration hides the actual failure mode: a fast pipeline that is fast for the wrong jobs and still slow for the one PR that matters.
The decision, concretely
- Every PR still runs every job regardless of what changed? Add path-based change detection first. It is the single change that pays off the most and everything else compounds on top of it.
- Shared packages exist that multiple services depend on? Make sure your path filters trigger downstream services on shared-package changes, not just the folder that changed.
- Cache hit rate is good but the pipeline still feels slow? Check whether lint and unit tests are gating the heavy build, or running in parallel with it and hiding a fast failure behind a slow one.
- Growing past roughly 15 services? Move from ad-hoc
ifconditions todorny/paths-filterand reusable workflows before the workflow file itself becomes the maintenance burden.
Questions people ask
How do I run a GitHub Actions job only when a specific folder changes?
For a whole workflow, add paths: under the pull_request or push trigger, for example paths: ['apps/api/**']. For individual jobs inside one workflow, run dorny/paths-filter in a first job, expose its outputs, and put if: needs.detect_changes.outputs.api_changed == 'true' on the downstream job. The job-level approach is what monorepos need, because one workflow can then serve every service.
Why is my pull request stuck on a pending required check after adding path filters?
GitHub's docs state that when a workflow is skipped by path or branch filtering, its checks stay "Pending", and a PR that requires them cannot merge. Trigger-level paths: filters cause this with required checks. The fix is to keep the workflow always running and skip inside it with job-level if: conditions, since GitHub documents that a skipped job reports "Success" and does not block a merge.
Should shared packages trigger every service's CI?
Yes, for every service that imports them. List the shared path in each service's filter, as the packages/shared/** lines above do. Skipping this is the most common way a "fast" pipeline stops testing code that actually broke. Once the dependency graph gets too large to maintain by hand, use your build tool's affected-graph command instead of hand-written filters.
The call we'd make
Do not reach for a bigger runner before you have change detection. The teams that fix monorepo CI durably are not the ones who cut a few minutes off a build; they are the ones who gave each service an explicit ownership boundary in the pipeline itself, so a docs change costs seconds and a real change still gets full coverage. Pin the actions you depend on, too: GitHub Actions security hardening covers why third-party actions like dorny/paths-filter belong on a commit SHA in production. That boundary is also what keeps main trustworthy as the repo grows past the size where anyone can hold the whole dependency graph in their head.
Sources
Cite this article
Kiril Urbonas (2026). GitHub Actions for Monorepos: Fast CI Without Pipeline Chaos. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/github-actions-monorepo-fast-ci-2026-02-24
[GitHub Actions for Monorepos: Fast CI Without Pipeline Chaos](https://www.devopsness.com/blog/github-actions-monorepo-fast-ci-2026-02-24) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.