How to Build Only Changed Paths in CI for a Large Repo
An on.push.paths filter stops a workflow from running at all when nothing in its area changed, the cheapest possible skip.
The least work is work you never start. For a large repo, give each buildable area its own workflow with a paths filter so unrelated commits do not trigger it. This complements diff-based gating inside a job.
Steps
- Give each area its own workflow file.
- Add
paths:globs for that area under push and pull_request. - Add a placeholder required check so branch protection still passes on skips.
Workflow
.github/workflows/api.yml
name: api
on:
push:
paths:
- 'services/api/**'
- '.github/workflows/api.yml'
pull_request:
paths:
- 'services/api/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd services/api && npm ci && npm testGotchas
- A required check that never runs blocks merges; add a trivial always-pass job as a stand-in.
- paths filters do not fire on schedule or workflow_dispatch, so those still run everything.
Related guides
How to Detect Changed Areas With dorny/paths-filter in CIUse dorny/paths-filter in GitHub Actions to compute which areas of a large repository changed and gate downst…
How to Find Changed Files With Git Diff in CIList the files a push or pull request changed in CI with git diff --name-only against the base ref, driving p…