Sub topic 3
Required Status Checks and Branch Protection
Assume you know basic Git and pull requests, have used a CI system, and understand lint, unit, and integration tests.
Required status checks and branch protection
A required status check is a named CI result that must pass before a pull request can merge. Branch protection is the repository rule that enforces this condition.
Require only checks that protect against common merge failures. Keep names stable, such as pr / fast-checks. Avoid requiring a job that runs only for unusual files or only on a schedule.
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 testEnable the matching check in branch protection. Also require the pull request to be up to date before merging when changes frequently conflict.
Running fewer checks with path filters
Path filters select workflows based on changed files. They can reduce cost, but a skipped workflow may leave a required check pending forever.
on:
pull_request:
branches: [main]
paths:
- "src/**"
- "package.json"Do not make this filtered workflow a required check unless every pull request always receives a valid result. Instead, use separate required checks that always start, or move the path condition into a job while keeping a reporting job active.
Keeping flaky tests from blocking merges
A flaky test passes and fails without a relevant code change. Quarantine it from required checks, record each failure, and assign an owner. Keep a small non-blocking job that reports its status. Restore the test to the required set after its cause is fixed.
Owning and triaging nightly failures
Nightly jobs should have an owner and a defined response time. Classify each failure as a product defect, test defect, environment failure, or known flake. Link the failure to an issue, preserve logs and artifacts, and remove obsolete exceptions.
Runtime budgets, caching, and parallelism
Set a time budget for each stage. Cache dependencies, split independent test groups across workers, and cancel obsolete pull-request runs. Measure cache savings against stale-cache failures.
Reviewing and moving checks over time
Review runtime, failure rate, flaky rate, and escaped-defect data. Move a check earlier when it detects frequent merge failures cheaply. Move it later when it is slow, redundant, or too noisy.
Exercise
A path-filtered workflow is required, but documentation-only pull requests remain blocked. What should you change?
Show answer
Remove that workflow from the required checks, or keep an always-running reporting workflow that returns a valid result for every pull request.