Sub topic 10
Status checks and CI on pull requests
This chapter assumes you can open a pull request and read a diff. You should also know what a YAML file is and have a repository where you can push a workflow.
What a status check is
A status check is a pass or fail signal attached to a specific commit. It comes from an outside system, usually a continuous integration (CI) service that builds the code and runs tests. GitHub shows each check on the pull request, next to the merge button.
A check has one of a few states: pending, success, failure, or skipped. A pull request is only as healthy as the latest commit on its head branch. When you push a new commit, GitHub runs the checks again against that commit.
Running tests with GitHub Actions
GitHub Actions is GitHub's built-in CI. A workflow is a YAML file in .github/workflows/ that says when to run and what to do. This one runs tests on every pull request that targets main.
name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm testThe on: pull_request trigger starts the workflow when a pull request is opened, updated, or reopened. Each job under jobs appears as its own check. The check name is test here, because that is the job key. Use this name when you configure required checks.
Reading the results
The merge box lists every check with a status and a Details link. Click it to open the job log. Find the first failing step. Later errors are often side effects of the first one.
To see the same information in a terminal, run gh pr checks 123.
Required checks
A check only blocks a merge if you mark it as required. You do this in a branch protection rule or a ruleset, which a later chapter covers. Select the check by name. If a required check never reports, the pull request stays blocked and waits for it.
Common errors
- Check never starts. The workflow's
branchesfilter or path filter does not match the pull request. Also, a workflow file with a YAML syntax error is silently not run. Look at the Actions tab for the error. - Required check is stuck on "Expected". The check name in the rule does not match the job name, or the workflow was skipped by a filter. A skipped workflow never reports, so the check never arrives.
- Passes locally, fails in CI. CI starts from a clean machine. Missing environment variables, a different Node version, or files you did not commit are the usual causes.
- Flaky tests. A test that fails at random teaches people to click "Re-run" and ignore red. Fix or quarantine it instead.
- Fork pull requests lack secrets. Workflows triggered from forks run with a read-only token and no repository secrets. This protects you from untrusted code.
Exercise
A required check named "test" shows "Expected — Waiting for status to be reported" for a pull request that only changes README.md. The workflow has a paths filter that ignores Markdown files. Why is the pull request stuck?
Show answer
The paths filter caused GitHub to skip the workflow, so no check named "test" was ever reported. A required check that never reports is treated as missing and blocks the merge. Fix it by removing the path filter, or by adding a lightweight job with the same name that always reports success for those changes.