Skip to content
Latchkey

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 paths globs under on.push and on.pull_request for each service.
  • Use paths-ignore for 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 test

Tradeoffs

  • 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

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