How to Detect Changed Areas With dorny/paths-filter in CI
dorny/paths-filter reads the diff and emits a boolean per named filter, which downstream jobs use in their if conditions.
When you want one workflow to decide which of several areas changed, dorny/paths-filter computes named filters and exposes them as outputs. Downstream jobs gate on those outputs, so unchanged areas skip without a separate workflow each.
Steps
- Run
dorny/paths-filterwith named filters mapping to globs. - Read
steps.filter.outputs.<name>in a job-levelif. - Give each area its own job gated on its filter output.
Workflow
.github/workflows/ci.yml
jobs:
changes:
runs-on: ubuntu-latest
outputs:
api: ${{ steps.filter.outputs.api }}
web: ${{ steps.filter.outputs.web }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
api:
- 'services/api/**'
web:
- 'apps/web/**'
build-api:
needs: changes
if: needs.changes.outputs.api == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd services/api && npm ci && npm testGotchas
- On pull_request it diffs against the base automatically; on push it needs history, so fetch the base.
- Outputs are strings; compare with
== 'true', not a bare boolean.
Related guides
How to Build Only Changed Paths in CI for a Large RepoSkip unnecessary work in a large repository by building only the paths a change touched in GitHub Actions, us…
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…