Skip to content
Latchkey

How to Run Only Affected Jobs on Changed Paths in GitHub Actions

A change-detection job exposes per-area booleans that downstream jobs gate on, so untouched services never build.

Run dorny/paths-filter once to compute which areas changed, expose the result as job outputs, and put an if: on each build job that reads needs.changes.outputs.<area>.

Steps

  • Add a changes job that runs dorny/paths-filter with named filters.
  • Expose each filter result as a job outputs: entry.
  • Gate each build job with if: needs.changes.outputs.<area> == 'true'.

Workflow

.github/workflows/ci.yml
jobs:
  changes:
    runs-on: ubuntu-latest
    outputs:
      api: ${{ steps.f.outputs.api }}
      web: ${{ steps.f.outputs.web }}
    steps:
      - uses: actions/checkout@v4
      - id: f
        uses: dorny/paths-filter@v3
        with:
          filters: |
            api: 'services/api/**'
            web: 'services/web/**'
  build-api:
    needs: changes
    if: needs.changes.outputs.api == 'true'
    runs-on: ubuntu-latest
    steps:
      - run: echo build api

Gotchas

  • A required check that is skipped can block merges; add a passing gate job that always succeeds.
  • On the first push of a new branch the filter compares against the base, so a wide diff runs everything.

Related guides

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