How to Run Per-Package Jobs With dorny/paths-filter in GitHub Actions
dorny/paths-filter emits one boolean output per named filter, which you use as an if guard on each package job.
Run dorny/paths-filter once in a detect job to classify the diff, expose its outputs, then gate each downstream package job with if: needs.detect.outputs.<name> == 'true'.
Steps
- Add a
detectjob that runsdorny/paths-filterwith a filter per package. - Promote each filter result to a job output.
- Add
needs: detectand anif:to each package job.
Workflow
.github/workflows/ci.yml
jobs:
detect:
runs-on: ubuntu-latest
outputs:
api: ${{ steps.f.outputs.api }}
web: ${{ steps.f.outputs.web }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: f
with:
filters: |
api: 'packages/api/**'
web: 'packages/web/**'
api:
needs: detect
if: needs.detect.outputs.api == 'true'
runs-on: ubuntu-latest
steps:
- run: echo "build api"Gotchas
- Outputs are strings, so compare with
== 'true', not as a raw boolean. - A required check that is skipped can block merges; pair gated jobs with a status aggregator.
Related guides
How to Generate a Job Matrix From Changed Directories in GitHub ActionsBuild a GitHub Actions matrix at runtime from the directories a PR changed, emitting JSON to a job output and…
How to Detect Changed Packages With pnpm Filters in GitHub ActionsRun scripts only for changed pnpm workspace packages in GitHub Actions using pnpm --filter "...[ref]", which…