forge
Clone
0 watching0 forksRustAGPL-3.010.7 MiBa169f73Tahinli1 month ago255 commits
Merge queue
A protected branch can require the merge queue. Then the branch only ever moves to commits that CI has tested, and pull requests that were tested against an older tip cannot land on a newer one by accident.
Turning it on
Open the repo's settings, go to branch protection and edit the rule for the branch (usually
main). Tick Require merge queue and save. The rule's summary shows merge queue required.
With the option on:
- The merge box of a pull request shows Add to merge queue instead of Merge. The merge style select is kept. Auto-merge is not offered, and the direct merge endpoint refuses the branch.
- The pull request still has to pass the merge checks it would need for a direct merge: approvals, no changes requested, and no conflicts. Its required status checks must also be green on its own head, so a pull request that has not passed CI yet cannot enter the queue. An outdated head does not block it, because the queue tests it on the current tip.
- Once queued, the merge box shows Position N in the merge queue and a Remove from queue button.
How an entry moves
Entries are kept per target branch, in the order they joined.
- queued: waiting for the entries ahead of it.
- testing: the head of the queue. The forge merges the current tip of the branch and the
pull request head with the merge style the person chose. The merge is made in the object
store, with no working tree, and named by the temporary ref
refs/forge/merge-queue/{branch}/{number}. A CI run tests that ref. - merging: the run passed and every required check is green on the candidate. The branch
moves from the tip the candidate was built on to the candidate, as a compare-and-swap. The
pull request is then marked merged, with the usual events, notifications and post-push work.
The entry leaves the queue with the reason
merged.
One thing sends an entry back, and it needs no person:
- The target moved before the swap. The candidate is built again on the new tip, and its run starts again. The entry keeps its place at the head.
An entry also ends early when:
- Failed (
tests_failed,checks_failed,conflict): the forge comments on the pull request, mentions the person who queued it, and links the failing run. The entry stays in the history with its reason. - Removed (
removed): someone pressed Remove from queue. - Removed (
head_changed,closed): the pull request's head moved, or it was closed while it waited. - Removed (
blocked,permission,no_branch): a merge check no longer passes, the person who queued it can no longer write to the repo, or the branch is gone.
When an entry finishes, the next one starts. Nothing polls: each step follows an event, a commit status on a candidate, a request that changes the queue, or a finished entry.
Testing candidates in CI
A candidate is a normal commit, so the workflow in .forge/ci.toml reads the candidate's own
files. The run is started with trigger merge_queue, on the commit of the candidate, and its
statuses (ci/<job>) are written to that commit. Required checks on the branch are read from
those statuses.
To pick which workflow runs, use the merge_queue key in [on]:
[on]
merge_queue = true
- With
merge_queue = true, the workflow's jobs run for every candidate. - Without it, a candidate runs the
pushjobs of its target branch, the same jobs that run when a commit lands there. If the workflow has nopushtrigger for the branch, the candidate has no run. - With no workflow file at the candidate, there is no run. The queue then lands the candidate once the required checks, if any, are green.
See CI for the other [on] keys.
Notes
- Batching is not supported yet: one pull request is tested at a time.
- The comments that the queue writes on a pull request are in English, whatever the viewer's language.
- The queue page is at
/{owner}/{repo}/merge-queue. It lists the waiting entries with their position, state, CI run and a remove button.?show=historylists the finished entries. The page follows changes live. - A queued pull request's candidate is kept under
refs/forge/merge-queue/. Those refs are temporary; once an entry finishes, its ref is left in place until the next candidate of the same pull request replaces it.