Sub topic 14
Merge queue as a rule
This chapter assumes you can write a basic GitHub Actions workflow and have read the earlier chapters on required status checks and rulesets.
The problem a queue solves
Two pull requests can each pass their checks against main and still break the build once both are merged. The usual fix is the "require branches to be up to date" setting (strict in the API). That setting forces every author to update their branch and wait for CI again each time another pull request merges. With many open pull requests, this becomes a race.
A merge queue removes the race. Approved pull requests join a queue. GitHub builds a temporary branch for each entry that contains the latest main, every entry ahead of it in the queue, and the pull request itself. Required checks run on that temporary branch. If they pass, the pull request merges. If they fail, it leaves the queue and the entries behind it are rebuilt without it.
Enabling it as a ruleset rule
In a ruleset, the queue is a rule of type merge_queue. Add it to the rules array of a branch ruleset. The same setting exists as "Require merge queue" in classic branch protection, but only a ruleset lets you combine it with bypass actors and evaluate mode.
{
"type": "merge_queue",
"parameters": {
"check_response_timeout_minutes": 60,
"grouping_strategy": "ALLGREEN",
"max_entries_to_build": 5,
"max_entries_to_merge": 5,
"merge_method": "SQUASH",
"min_entries_to_merge": 1,
"min_entries_to_merge_wait_minutes": 5
}
}| Parameter | Meaning |
|---|---|
| `merge_method` | How entries land: `MERGE`, `SQUASH`, or `REBASE`. |
| `grouping_strategy` | `ALLGREEN` requires every entry in a group to pass its own checks. `HEADGREEN` requires only the last entry's checks to pass. |
| `max_entries_to_build` | How many temporary branches are tested at once. |
| `min_entries_to_merge`, `min_entries_to_merge_wait_minutes` | Lets GitHub wait for a group to fill before merging. |
| `check_response_timeout_minutes` | How long to wait for required checks before failing the entry. |
Make your workflows run for the queue
Required checks run on the temporary branch, not on the pull request. GitHub starts them with the merge_group event. If your workflow listens only for pull_request, the required check never reports on the queue entry. The entry then waits until the timeout and is removed.
name: ci
on:
pull_request:
merge_group:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make testThe job name build must match the context in your required_status_checks rule.
Exercise
After you enable a merge queue, pull requests are approved and enter the queue, but every entry is removed after the timeout. The required check build passes normally on the pull request itself. What is the most likely cause, and what is the fix?
Show answer
The build workflow does not trigger on the merge_group event, so no result is reported for the temporary queue branch. Add merge_group: to the workflow's on: section. Confirm the job name still matches the required check context.