Sub topic 6
Running workflows on merge_group
This chapter assumes you know GitHub Actions workflow syntax, how required status checks work, and that a merge queue is already enabled on your branch. Here you will make your workflows report a status inside the queue.
Why the trigger is needed
When a pull request enters the queue, GitHub creates a temporary branch whose name starts with gh-readonly-queue/. That branch holds the latest base branch plus the changes queued ahead of it. GitHub then waits for your required checks to report on that commit.
A workflow that only listens to pull_request does not run on that branch. The required check never reports, and the pull request waits until the check times out and the queue removes it. The fix is to add the merge_group event to every workflow that provides a required check.
Adding the trigger
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 test job now runs twice for each change. It runs on the pull request, and it runs again on the temporary merge group commit. The second run is the one that proves the combined result is safe to merge.
checks_requested is the only activity type for merge_group. You can leave out types, and the workflow behaves the same:
name: Lint
on:
pull_request:
merge_group:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linter
run: make lintWhat happens during a queue run
Details that cause trouble
- Filters differ from
pull_request. Thebranchesfilter onmerge_groupmatches the temporarygh-readonly-queue/...branch name, notmain. Use no filter unless you have a reason, because a filter that matchesmainwill skip the queue branch. - Path filters do not apply. A
pathsfilter is not supported formerge_group. If a workflow usespathsonpull_requestand the check is required, the check does not report on pull requests that skip it. To avoid that, run the workflow every time and skip work inside the job. - The job name must match. Required checks are matched by job or check name. If you rename a job, update the required check setting too, or the queue waits for a name that never reports.
- Checkout gets the merge group commit. On this event
actions/checkoutchecks out the temporary commit by default, so your tests run against the combined code. You don't need to set aref. - Other events don't count. A status that comes from
pushorpull_requeston a different commit does not satisfy the queue. The check must report on the merge group commit.
Checking that it works
Add a pull request to the queue, then open the Actions tab. Look for a run with the event merge_group and a branch starting with gh-readonly-queue/. If the pull request sits in the queue with no such run, the workflow is missing the trigger, or the workflow file on the base branch doesn't contain it. The workflow definition is read from the merge group commit, so merge the trigger change into main before you rely on it.
Exercise
A pull request passes all checks, enters the queue, and then is removed after the check timeout with no check run shown. The workflow has on: pull_request: branches: [main]. What is wrong, and what is the fix?
Show answer
The workflow has no merge_group trigger, so it never runs on the temporary gh-readonly-queue/ commit and the required check never reports. Add merge_group: (optionally with types: [checks_requested]) to the on section, and merge that change into the base branch.
Exercise
A workflow uses merge_group with branches: [main]. Why does it not run in the queue?
Show answer
The branch filter on merge_group is matched against the temporary queue branch, whose name begins with gh-readonly-queue/, not against main. Remove the filter or match the queue branch name.