DevOps / GitHub Actions Interview Questions
How do you implement path filtering so a workflow only runs when specific files change?
GitHub Actions supports built-in path filtering on push and pull_request triggers via the paths: and paths-ignore: filters. When set, the workflow only fires if at least one file in the commit diff matches the given glob pattern.
on: push: branches: [main] paths: - 'backend/**' # any file under backend/ - 'Dockerfile' - '.github/workflows/backend-ci.yml' pull_request: paths-ignore: - '**.md' # skip when only docs changed - 'frontend/**'
You can use both paths and paths-ignore but not on the same trigger event simultaneously. Use paths when you want an allow-list and paths-ignore when you want to exclude certain patterns.
Monorepo scenario — for finer-grained per-step filtering (e.g., only run specific jobs when specific subdirectories changed), the community action dorny/paths-filter is widely used:
jobs: changes: runs-on: ubuntu-latest outputs: backend: ${{ steps.filter.outputs.backend }} frontend: ${{ steps.filter.outputs.frontend }} steps: - uses: actions/checkout@v4 - uses: dorny/paths-filter@v3 id: filter with: filters: | backend: - 'backend/**' frontend: - 'frontend/**' test-backend: needs: changes if: needs.changes.outputs.backend == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: ./gradlew :backend:test
The limitation of the built-in paths: filter is that it applies to the entire workflow; you cannot skip only certain jobs within it. dorny/paths-filter solves this by producing per-path boolean outputs that individual job conditions can check.
More Related questions...