Sub topic 2
What Belongs on Every Pull Request
Assume you know basic Git, pull requests, and CI systems. You should also know what linting, unit tests, and integration tests are.
A pull request (PR) check runs before code is merged. Its job is to catch common, high-signal failures while the author can still fix them quickly. Keep this stage fast and predictable.
Checks for Every Pull Request
Run checks that are:
- Relevant to most changes.
- Deterministic, meaning they usually give the same result for the same code.
- Fast enough to provide feedback within a few minutes.
- Useful for preventing broken code from entering the merge queue.
Typical PR checks include formatting, linting, type checking, unit tests, and a small set of focused integration tests. Build the application if compilation or packaging errors are common.
| Check | Why it fits a PR |
|---|---|
| Unit tests | Fast feedback with a narrow failure signal |
| Linting | Finds style and common code errors |
| Full end-to-end tests | Usually too slow and more environment-sensitive |
Checks at Merge Time and on Main
Merge-time checks protect the exact commit that will enter the default branch. A merge queue can test a temporary candidate containing the latest approved pull requests. Run integration tests there when they are too slow for every PR but still important before merging.
Run the same or a similar suite after each push to main. This confirms that the branch remains healthy and detects problems caused by interactions between changes.
Checks for Nightly Builds
Schedule expensive or broad checks for a nightly build. Examples include the complete end-to-end suite, compatibility testing across supported versions, long-running performance tests, and security scans that need more setup.
Nightly checks should produce actionable failures. Assign an owner and record whether a failure is a product defect, infrastructure issue, or flaky test. A test that fails repeatedly without triage will eventually be ignored.
Configuring the Three Triggers
GitHub Actions uses separate events for these stages:
name: checks
on:
pull_request:
branches: [main]
merge_group:
push:
branches: [main]
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
jobs:
fast:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
- run: npm test
broad:
if: github.event_name == 'merge_group' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:integration
nightly:
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:e2eExercise
Where should a deterministic unit test that runs in two seconds go?
Show answer
On every pull request, and usually again in the merge or main-branch workflow if that workflow uses a separate candidate.