Sub topic 16
Debugging and tuning your filters
This chapter assumes you have built a change-detection job with dorny/paths-filter, gated jobs with if, and added a gate job for required checks. Here you learn to find out why a filter did or did not fire, and how to adjust it.
Start with where the symptom appears
A workflow-level paths filter and a job-level if fail in different places. Use the symptom to pick the layer to inspect.
| Symptom | Likely layer | First check |
|---|---|---|
| No workflow run appears at all | Workflow `paths` filter | Does the glob match the changed file? Is the branch listed under `branches`? |
| Run appears, a job shows "skipped" | Job `if` | Which output was `false`? |
| Required check stays "Expected" | Skipped workflow and branch protection | Require only the gate job, and make sure its workflow always runs. |
| Job runs when it should not | Over-broad glob | Look for `**` on shared folders or the workflow file. |
Make the filter show its work
Do not guess what the filter matched. Ask it to list the files. The list-files option adds a <name>_files output for each filter.
changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
list-files: json
filters: |
backend:
- 'services/api/**'
- 'libs/shared/**'
- name: Report filter results
env:
BACKEND: ${{ steps.filter.outputs.backend }}
BACKEND_FILES: ${{ steps.filter.outputs.backend_files }}
run: |
{
echo "### Filter results"
echo "backend changed: $BACKEND"
echo "matched files: $BACKEND_FILES"
} >> "$GITHUB_STEP_SUMMARY"The values go through env instead of being written into the script. A file name is untrusted input, and interpolating it directly into run would let a crafted name inject shell commands.
The summary appears on the run page, so you can see exactly which files caused a job to run.
Common tuning problems
- A filter that is too wide. A pattern such as
libs/**makes every project rebuild on any library change. Narrow it to the libraries each project uses, such aslibs/shared/**for the projects that depend on it. - A filter that is too narrow. A change to a lockfile, a build script, or the workflow file itself skips the tests. Add those paths to every filter they affect, as the earlier examples do with the workflow file.
- Pull request and push disagree. On a pull request, the changed files are those in the whole pull request. On a push, they are the files in that push. A filter that works on one can behave differently on the other, so test both.
- Wasted runs on fast pushes. Add a
concurrencygroup withcancel-in-progressso an older run for the same pull request stops when a new commit arrives.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: trueExercise
A pull request changes only README.md at the repository root. The workflow has paths: ['services/api/**'], and branch protection requires a job from that workflow. The pull request cannot be merged. Why, and what is the fix?
Show answer
The paths filter stops the whole workflow from running, so the required check never reports and stays at "Expected". Remove the workflow-level filter. Run the workflow on every pull request, detect changes in a change-detection job, and require only an always-running gate job such as ci-ok.