Sub topic 5
What belongs on every pull request
Prerequisites and scope
This chapter assumes you know the basic Git and pull request workflow. It also assumes you have used a CI system such as GitHub Actions and know what linting, unit tests, and integration tests are. Earlier chapters covered how triggers and status checks work and how to classify checks by cost. This chapter applies that material to one stage: the checks that run on every pull request.
The examples use GitHub Actions. The reasoning carries over to GitLab CI and Jenkins.
The job of a pull request check
A pull request (PR) check answers one question for the author and the reviewer: "Is this change safe to review and likely safe to merge?" It does not need to prove the whole system works. Later stages exist for that.
Three properties define a good PR check:
- Fast. The author is waiting. A check that takes 3 minutes gets read. A check that takes 40 minutes gets ignored, and the author switches to other work and loses context.
- Deterministic. The same commit gives the same result. A check that fails at random teaches people to rerun it without reading the output.
- Attributable. When it fails, the failure points at something in the diff. If the cause is usually outside the change, the check does not belong here.
A useful budget is to keep the required PR checks under about 10 minutes of wall-clock time. This is a guideline, not a rule. Pick a number your team agrees on, and measure against it.
The admission test
A check earns a place on every PR when it passes all of these questions:
- Does it finish within your PR time budget, running in parallel with the other PR checks?
- Is it stable enough that a red result almost always means a real problem in the change?
- Does it catch a class of problem that is cheap to fix now and expensive to fix later?
- Does it need only what is available on the PR runner, such as the source code and public packages, without shared environments or production-like data?
If any answer is no, consider moving the check to merge time or to the nightly build, which later chapters cover.
Checks that usually pass the test
| Check | Typical runtime | Why it belongs on the PR |
|---|---|---|
| Linting and formatting | Seconds to 1 minute | Catches style and simple bugs. Fixes are trivial. |
| Type checking | 30 seconds to 3 minutes | Catches a large class of errors without running code. |
| Unit tests | 1 to 5 minutes | Fast, isolated, and directly tied to the changed code. |
| Build or compile | 1 to 5 minutes | Proves the change produces an artifact at all. |
| Dependency and secret scanning | Seconds to 2 minutes | A leaked secret is far cheaper to stop before merge. |
| Small contract or schema checks | Under 2 minutes | Catches breaking changes to interfaces early. |
Runtimes are rough. Your project may differ by a large factor, so measure your own.
A baseline PR workflow
The following workflow runs lint and unit tests on pull requests that target main. It is the minimal version of the idea.
name: pr
on:
pull_request:
branches: [main]
jobs:
fast-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm testSeveral details matter here.
on: pull_requestwithbranches: [main]runs the workflow for PRs whose base branch ismain. A PR targeting a release branch will not trigger it unless you list that branch.actions/checkout@v4checks out a temporary merge commit of the PR head and the base branch by default. So the tests run against the result of merging, not only against the author's branch. This catches some conflicts with recent changes tomain, but the merge commit can be stale ifmainmoves afterward.cache: npmrestores the npm download cache between runs. It speeds upnpm ci. It does not skip installation.npm ciinstalls exactly what the lockfile says and fails if the lockfile andpackage.jsondisagree. That failure is useful on a PR.
Splitting one job into several
The baseline runs lint and tests in sequence in one job. If lint takes 40 seconds and tests take 4 minutes, the total is about 5 minutes, and a lint failure is reported only after install. Splitting into parallel jobs gives faster, clearer signals.
name: pr
on:
pull_request:
branches: [main]
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm testThe concurrency block cancels an older run of the same PR when the author pushes again. Without it, stale runs keep consuming runners and can report results for commits nobody cares about anymore.
Parallel jobs trade runner minutes for wall-clock time. Each job repeats checkout and install. For small projects, that overhead can exceed the savings. Split when the slowest job is long enough that parallelism clearly wins, and keep cheap checks together otherwise.
What to keep off the PR
Some checks look natural on a PR but cause problems there.
- Full end-to-end suites. They are slow and often flaky. A 45-minute suite on every push wastes author time. Run it nightly, or at merge time if the risk justifies it.
- Tests that need shared environments. Two PRs running at once can corrupt each other's data in a shared staging database.
- Tests that need secrets. On GitHub, workflows triggered by PRs from forks do not receive repository secrets, so such tests fail for outside contributors. Do not work around this with
pull_request_targetunless you understand the security implications, since it runs with elevated permissions in the context of the base repository. - Performance benchmarks. Shared runners are noisy, so timing results vary. Benchmarks produce unreliable pass or fail signals on a PR.
- Broad compatibility matrices. Running every OS and language version on every PR multiplies cost. Test one primary combination on the PR and the full matrix later.
Common errors
- Running everything "to be safe." The PR becomes slow, authors stop waiting for it, and they start merging on red or batching changes into huge PRs. Slower feedback leads to worse changes.
- Keeping a flaky check as required. If a test fails 1 time in 20, then with many PRs per day somebody is blocked every day. People learn to click rerun. Quarantine or fix the test. A later chapter covers this.
- Marking jobs required by name, then renaming them. Branch protection matches the job's reported check name. If you rename a job, the old required name never reports, and the PR waits forever for a check that will not arrive.
- Using
pathsfilters on a required workflow. If the workflow does not run because of a path filter, its required check stays pending and blocks the merge. Path filters have their own chapter. - Treating the PR merge commit as final. A PR can pass against an older
mainand still break after merge. That gap is why a merge stage exists.
Choosing what to include: a worked example
Suppose a Node service has these checks and measured runtimes:
| Check | Runtime | Failure rate from flakiness | Needs shared environment |
|---|---|---|---|
| ESLint | 40 seconds | Near 0% | No |
| TypeScript type check | 1.5 minutes | Near 0% | No |
| Unit tests | 4 minutes | Under 0.5% | No |
| API integration tests | 14 minutes | About 3% | Yes, a test database |
| End-to-end browser tests | 50 minutes | About 8% | Yes, staging |
Apply the admission test.
- ESLint, type check, and unit tests are fast, stable, and self-contained. They go on the PR. Run in parallel, the slowest is 4 minutes.
- API integration tests exceed a 10-minute budget and need a database. They fail the test on runtime and environment. Move them to merge time, or run them on the PR only for changes that touch the API code, using path filters.
- End-to-end tests fail on runtime, flakiness, and environment. They go to the nightly build.
The result is a PR feedback loop of about 4 minutes, with the slower checks still running somewhere before release.
Making PR failures easy to act on
Speed is not the only property of a good PR check. The output must tell the author what to do next.
- Print the failing test name and assertion, not only the exit code.
- Upload test reports or logs as artifacts when a job fails, so the author does not have to reproduce the failure locally to read them.
- Keep each job's name descriptive, such as
unit-testsrather thanjob1, because the name appears in the PR status list and in branch protection rules. - Make the commands the same locally and in CI, for example by using
npm run lintin both places. An author who can reproduce a failure in one command fixes it faster.
Summary of the decision
Put a check on every PR when it is fast, stable, tied to the diff, and runnable without shared state. Run the cheap checks in parallel, cancel stale runs, and measure the result. Everything else moves to a later stage, and the next chapter covers the first of those: merge time and the main branch.
Exercise
Your team's PR workflow has a 12-minute budget. A proposed check, "integration-tests", takes 9 minutes alone, uses a shared staging database, and fails randomly about 4% of the time. Lint and unit tests already take 5 minutes in parallel. Should it be a required check on every PR? Name the admission-test questions it fails and say where you would place it instead.
Show answer
No. It fails the admission test on three counts. Runtime: added to the existing checks it is still within budget only if run in parallel, but it leaves little room, and its 9 minutes dominate the feedback loop. Stability: a 4% random failure rate means a red result often does not point at the change, so people will rerun instead of reading. Environment: the shared staging database means concurrent PRs can interfere with each other, which also causes false failures. Place it at merge time (merge queue or push to main), where it runs once per candidate commit instead of on every push, and fix the flakiness and database isolation before relying on it as a blocking gate. A path-filtered, isolated version could run on PRs that touch the relevant code.
Exercise
A developer renames the job fast-checks to checks in the PR workflow. Afterward, every new PR shows "Expected, waiting for status to be reported" and cannot merge, even though all jobs are green. What happened and how do you fix it?
Show answer
Branch protection still lists the old check name fast-checks as required. No job reports under that name anymore, so GitHub waits for a status that will never arrive. Fix it by updating the required status checks in the branch protection settings (or ruleset) to the new name checks, then confirm on a test PR that the status list shows the required check reporting.