How to Use Path Filters to Avoid Unneeded CI
A path filter stops a service from rebuilding when only an unrelated directory changed.
In a monorepo, an unfiltered workflow rebuilds and retests everything for a one-line change in one package. Scoping each workflow with paths runs only the pipelines a commit actually affects.
Steps
- Add
pathsglobs underon.pushandon.pull_requestfor each service. - Use
paths-ignorefor changes that never need a build. - Keep one workflow per deployable unit so they trigger independently.
Workflow
.github/workflows/api.yml
on:
push:
paths:
- 'services/api/**'
- '.github/workflows/api.yml'
jobs:
build-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd services/api && npm ci && npm testTradeoffs
- Path filters apply to push and pull_request, not to schedule or workflow_dispatch.
- A skipped required check needs a placeholder success job or it blocks the merge.
Related guides
How to Skip Redundant CI Runs to Cut WasteStop CI from running work that no commit needs by using concurrency cancel-in-progress and paths filters, cut…
How to Run Only Tests Affected by a ChangeRun only the tests affected by a diff using test-impact selection, so CI stops re-running the whole suite for…