Sub topic 4
A decision framework for where a check belongs
This chapter gives you a repeatable way to place a check at the pull request (PR), merge, or nightly stage. It assumes you know what lint, unit tests, and integration tests are. It also assumes you have used a CI system such as GitHub Actions and understand status checks. The earlier chapters covered the speed and confidence trade-off and the cost profile of each kind of check. Here you combine them into a decision.
Why use a framework
Without a rule, teams place checks by habit. A check gets added to the PR workflow because that is where the last one went. Over time PRs slow down, and developers start to ignore the results or merge around them.
A framework turns placement into a short list of questions. Two people answering the same questions should reach the same stage.
The four questions
Ask these in order for each check.
- How long does it take? Measure the typical runtime on your CI hardware, including setup. A check that finishes in a few minutes can run on every PR. A check that takes tens of minutes or hours cannot.
- How often does it fail for reasons unrelated to the change? This covers flakiness, shared test environments, and third-party services. Checks with noisy results should not block PRs.
- How much does a failure cost if it is found late? If a late failure is cheap to find and fix, you can defer the check. If it would break main or block other developers, run it earlier.
- Can the failure be traced to one change? A check that runs on a single PR points to one author and one diff. A nightly run covers many commits, so someone must work out which commit broke it.
Turning answers into a stage
Use the answers as a decision path.
The thresholds are examples. Pick numbers that suit your team and write them down. A common starting point is under 10 minutes for PRs and under 30 minutes for merge time. Anything longer goes to the nightly run.
Worked example
Consider four checks in a Node.js project.
| Check | Runtime | Stability | Stage |
|---|---|---|---|
| ESLint | 1 min | Stable | Pull request |
| Unit tests | 4 min | Stable | Pull request |
| Integration tests against a database | 18 min | Stable | Merge |
| Browser end-to-end suite | 90 min | Occasional timeouts | Nightly |
The end-to-end suite fails question 1 and question 2, so it goes to the nightly run. The integration tests are too slow for every push but are stable, so they run on the candidate commit before it lands on main.
Overrides to the default path
The path gives a starting point. Some situations justify an exception.
- Risk. A fast security scan that catches leaked secrets belongs on the PR even if it is somewhat noisy, because a late finding is costly.
- Path relevance. A check that only matters for one directory can stay on the PR if it runs only when that directory changes. Path filters are covered in a later chapter.
- Cost. A check that needs expensive hardware, such as a GPU runner, may be moved later even if it is fast.
Record each override and the reason. Otherwise the next person will see an exception and assume the framework is optional.
Writing the decision down
Keep a short table in your repository, such as docs/ci-checks.md. For each check, list the stage, the runtime at the last review, the owner, and the reason for placement. This makes later reviews quick, because you compare current data with the recorded decision.
Exercise
A contract test suite takes 12 minutes, passes reliably, and catches API-breaking changes that would block three other teams if they reached main. Using the four questions, where should it run, and which question decides it?
Show answer
Run it at merge time, on the merge queue or main candidate commit, or on the PR if your PR budget allows 12 minutes. Question 3 decides it, because a late failure is expensive for other teams. Question 1 argues against running it on every PR push, since 12 minutes exceeds a typical PR budget of about 10 minutes. Question 2 passes because the suite is stable, and question 4 passes because each failure traces to one change.