Sub topic 5
Required checks in a queued world
This chapter assumes you know basic Git branching and merging, pull requests and code review on GitHub, branch protection rules or repository rulesets, and GitHub Actions workflow syntax. It also assumes you know what a required status check is. You should have a merge queue enabled or be about to enable one, as covered in the previous chapter.
Two places where a required check must pass
Without a queue, a required status check is evaluated once, on the pull request's head commit. With a queue, the same check is evaluated twice:
- On the pull request. The checks must pass before the pull request can be added to the queue. The pull request's head commit is what gets tested here.
- On the merge group. After the pull request enters the queue, GitHub builds a temporary merge group branch. That branch holds the latest base branch, the changes queued ahead of the pull request, and the pull request's own changes. The required checks must pass again on that commit.
The list of required checks you configure in the branch protection rule or ruleset is used for both. GitHub does not ask you for a separate "queue checks" list. So a check named test must report a status under the name test on the pull request commit and on the merge group commit.
The second evaluation is the reason the queue exists. It tests the combination that will land on main, not each pull request alone.
What happens when a required check never reports
GitHub does not run your workflows for you on the merge group. Whether a workflow runs is decided by its on: section. Most workflows are written like this:
on:
pull_request:
branches: [main]A workflow with only this trigger does not start for a merge group. The required check then never reports on the merge group commit. GitHub waits for it until the queue's check response timeout expires. After that it treats the merge group as failed and removes the pull request from the queue.
This is the most common reason a first merge queue "does nothing and then ejects everyone". The next chapter covers the merge_group trigger in detail. Here the point is the rule it enforces: every workflow that produces a required check must also run on the merge_group event.
name: CI
on:
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make testThe checks_requested type is the only activity type for merge_group, so you may leave out types.
name: Lint
on:
pull_request:
merge_group:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linter
run: make lintFor a merge_group run, actions/checkout checks out github.sha, which is the head commit of the merge group branch. You do not need extra checkout options to test the combined code.
Check names must match
GitHub matches required checks by name, and the name is the job's name (or its job ID if there is no name). Three details affect this.
- Same name on both events. If the
pull_requestrun and themerge_grouprun come from the same job, the names match automatically. Problems appear when you build separate workflows for each event and name the jobs differently. - Matrix jobs. A matrix job reports one check per combination, such as
test (ubuntu-latest, 20). The required list must contain those exact names. Changing a matrix value renames the check, and the old required name never reports again. - Renames break the requirement. If you rename a job, update the required checks list in the same change window. Otherwise the old name stays required and nothing reports it.
Skipped jobs and filtered workflows
Skipping behaves differently depending on where the skip happens.
| How the check is skipped | What GitHub reports | Effect on a required check |
|---|---|---|
| A job is skipped by its own `if:` condition | The job reports as skipped | Counts as passing |
| A whole workflow is skipped by `paths` or `branches` filters | No check run is created | The check stays pending and blocks |
| A job is skipped because a `needs` job failed | The job reports as skipped | Counts as passing, which can hide the failure |
The last row deserves attention. If deploy-check needs build and build fails, deploy-check is skipped. A required check that is merely skipped is treated as satisfied. You can end up with a failed upstream job that is not itself required, a skipped downstream job that is required, and a green result.
Path filters add a second risk in a queue. A merge group contains the changes of several pull requests, and a filter that depends on the paths changed by a single pull request is a poor fit for it. Keep the merge_group trigger unfiltered, and do any change detection inside the workflow instead.
A single gate job
One fix for both problems is a gate job. It depends on all the real jobs and is the only check you mark as required. It runs even when its dependencies fail, and it fails if any of them did not succeed.
name: CI
on:
pull_request:
merge_group:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linter
run: make lint
ci-gate:
needs: [test, lint]
if: always()
runs-on: ubuntu-latest
steps:
- name: Fail unless every needed job succeeded
env:
RESULTS: ${{ join(needs.*.result, ' ') }}
run: |
echo "Results: $RESULTS"
for r in $RESULTS; do
if [ "$r" != "success" ]; then
echo "A required job did not succeed"
exit 1
fi
doneMark ci-gate as the only required status check. Adding or renaming jobs behind it no longer requires a change to the ruleset. The gate also treats a skipped dependency as a failure, which closes the gap in the table above. If some jobs are legitimately skipped, loosen the loop to accept skipped for those jobs.
Checks from outside GitHub Actions
Required checks do not have to come from Actions. Many teams use an external CI system that reports commit statuses or check runs through the API or a GitHub App. Those systems need to cover the merge group too.
- The merge group commit lives on a branch named like
gh-readonly-queue/main/pr-123-<sha>. An external system that only builds pull request events or only specific branch names will never build it. - The status must be posted to the merge group's head commit SHA. In Actions you can read it from
github.event.merge_group.head_sha. - The context name must match the required check name exactly.
If you use such a system, test it with a throwaway pull request and watch the queue before relying on it.
Checks that are no longer needed
Without a queue, teams often turn on "Require branches to be up to date before merging" so that a pull request is re-tested against the latest main. That setting forces developers to click "Update branch" and wait for CI again, usually several times. The queue does this testing for you on the merge group commit, so the setting is unnecessary. Dropping it is one of the main usability gains of the queue.
Verifying the setup
Before announcing the queue to the team, run a short test.
- Open a trivial pull request against
mainand wait for its required checks to pass. - Add it to the merge queue.
- Open the Actions tab and look for runs triggered by
merge_group. The branch name starts withgh-readonly-queue/main/. - Compare the check names on that run with your required list. Every required name must appear.
- Confirm that the pull request merges.
If a required name is missing from step 4, fix the workflow trigger or the name and repeat with a new pull request.
Exercise
A team enables a merge queue on main. Their workflow has on: pull_request only, and the job test is a required check. Pull requests pass on the pull request page, join the queue, and are removed about an hour later. What is wrong, and what is the smallest fix? Also say what you would change if they later want to require two jobs, test and lint, without editing the ruleset whenever a job is added.
Show answer
The workflow does not run on the merge_group event, so test never reports on the merge group commit. GitHub waits until the check response timeout, then removes the pull request. The smallest fix is to add merge_group: (optionally with types: [checks_requested]) under on:. For the second part, add a gate job with needs: [test, lint] and if: always() that fails unless every needed job succeeded, and make only the gate job a required check.