Skip to content
Latchkey

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-filter with named filters mapping to globs.
  • Read steps.filter.outputs.<name> in a job-level if.
  • 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 test

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →