Sub topic 5
How GitHub decides which files changed
This chapter assumes you can read a workflow file and know what a commit, a branch, and a pull request diff are. A paths filter only works as well as your picture of the file list GitHub compares it against, so this chapter covers where that list comes from.
Two kinds of diff
GitHub builds the changed-file list differently for each trigger.
| Trigger | Comparison | What it means |
|---|---|---|
| `push` | Two-dot diff | Files that differ between the commit before the push and the commit after it |
| `pull_request` | Three-dot diff | Files that differ between the latest commit on the topic branch and the commit where it last diverged from the base branch |
A push covers everything in that one push, even if it contains several commits. A pull request covers everything the branch changed relative to its merge base. Commits that landed on the base branch after you branched do not appear in the list.
A worked example
Take this filter:
on:
pull_request:
paths:
- 'services/api/**'Suppose you branch from main and change only apps/web/index.js. Meanwhile, a teammate merges a change to services/api/server.py into main. Your pull request does not trigger the workflow. The three-dot diff starts at your merge base, so the teammate's file is not in your list.
The same teammate's push to main would trigger a push workflow with this filter. The two-dot diff for that push contains services/api/server.py.
Limits and special cases
- 300 files. GitHub only evaluates the first 300 changed files. If the matching file sits beyond that point, the workflow does not run.
- 1,000 commits. If a push contains more than 1,000 commits, or GitHub cannot generate the diff in time, the workflow always runs.
- Tags. Path filters are not evaluated when you push a tag.
- Combined filters. If you use
branchesandpathstogether, both must match.
What "no run" looks like
When a filter excludes an event, GitHub creates no workflow run at all. The run does not appear as skipped. It does not appear at all. For a workflow that is a required status check, the check stays at "Expected" and the pull request cannot merge. Later chapters cover this problem and its fix, a gate job.
Checking your assumptions
To see which files a pull request contains, run the same three-dot diff locally:
git fetch origin main
git diff --name-only origin/main...HEADRun it before debugging a filter. If your expected file is not in this output, the filter was never going to match.
Exercise
A pull request branch was created from main last week. Since then, someone merged a change to services/api/app.py into main. Your branch only edits README.md. The workflow uses on.pull_request.paths: ['services/api/**']. Does the workflow run for your pull request, and why?
Show answer
No. A pull request uses a three-dot diff from the merge base to the branch head, so it contains only your own changes. The edit to services/api/app.py landed on main after you branched, and it is not in your list. README.md does not match the pattern, so no run is created.
Exercise
Which two limits can cause a path-filtered workflow to behave unexpectedly on a very large push or pull request, and in which direction does each push the result?
Show answer
The 300-file limit can stop a workflow from running when the matching file is past the first 300 changed files. The 1,000-commit limit, or a diff timeout, makes the workflow always run, even if no file matches.