Sub topic 5
What belongs on every pull request
This chapter assumes you know the basic Git and pull request workflow, have used a CI system such as GitHub Actions, and know what linting, unit tests, and integration tests are. It covers which checks run on every pull request and why.
The purpose of a pull request check
A pull request (PR) check answers one question for the author: "Is this change safe enough to send to a reviewer?" The author is waiting for the answer, so speed matters more here than anywhere else in the pipeline. A check that takes 40 minutes on every push teaches people to switch tasks, batch their changes, or ignore the result.
A good PR check has three properties:
- Fast. The whole set finishes in roughly 10 minutes or less, and the first signal arrives within a few minutes.
- Deterministic. It gives the same result on the same code. A flaky check on every PR costs the whole team time on every PR.
- Actionable. When it fails, the author can tell from the log what to fix, without help from a platform team.
The default set
Apply those three properties and the usual PR set looks like this:
| Check | Why it belongs | Typical cost |
|---|---|---|
| Linting and formatting | Catches style and simple bugs in seconds | Under 1 minute |
| Type checking or compilation | Catches broken interfaces before runtime | 1 to 3 minutes |
| Unit tests | Cover logic in isolation with no network or database | 1 to 5 minutes |
| Build of the changed package | Confirms the change can be built at all | 1 to 5 minutes |
| Dependency and secret scanning (fast modes) | Blocks leaked credentials before review | Under 2 minutes |
Slower checks, such as integration suites, browser tests, and load tests, usually move to merge time or nightly runs. Later chapters cover those stages.
A working example
This GitHub Actions workflow runs lint and unit tests for pull requests that target main.
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 testTwo details keep it fast. cache: npm reuses downloaded dependencies between runs. npm ci installs exactly what the lockfile says, so results are repeatable.
Common errors
- Putting everything on the PR "to be safe." This slows feedback, and slow feedback gets bypassed. If a check fails rarely and takes 30 minutes, it is a merge or nightly candidate.
- Unit tests that secretly need services. A test that calls a real database or network is an integration test. It will fail intermittently on PRs.
- Skipping the check that matters most. If lint takes 20 seconds and catches real problems, never move it off the PR just to save a runner.
- No timeout. A hung job blocks the author indefinitely. Add
timeout-minutesto PR jobs.
A quick test for any check
Ask three questions. Does it finish in minutes? Does it fail only when the change is wrong? Can the author fix a failure alone? If all three answers are yes, it belongs on every pull request.
Exercise
Your team's integration suite takes 25 minutes and needs a test database. It has caught two real bugs this quarter, and it fails spuriously about once a week. Should it run on every pull request? Give two reasons.
Show answer
No. It is too slow for the author's feedback loop, since the PR budget is about 10 minutes. It also depends on external services and fails spuriously, so it would block merges for reasons unrelated to the change. It belongs at merge time or nightly, where a failure does not hold up an individual author. Fast unit tests that cover the same logic can stay on the PR.