forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits

merge-queue.md90 lines, 4.3 KiBHistoryRawDownload
1# Merge queue
2
3A protected branch can require the merge queue. Then the branch only ever moves to commits that
4CI has tested, and pull requests that were tested against an older tip cannot land on a newer one
5by accident.
6
7## Turning it on
8
9Open the repo's settings, go to branch protection and edit the rule for the branch (usually
10`main`). Tick **Require merge queue** and save. The rule's summary shows `merge queue required`.
11
12With the option on:
13
14- The merge box of a pull request shows **Add to merge queue** instead of **Merge**. The merge
15 style select is kept. Auto-merge is not offered, and the direct merge endpoint refuses the
16 branch.
17- The pull request still has to pass the merge checks it would need for a direct merge:
18 approvals, no changes requested, and no conflicts. Its required status checks must also be
19 green on its own head, so a pull request that has not passed CI yet cannot enter the queue.
20 An outdated head does not block it, because the queue tests it on the current tip.
21- Once queued, the merge box shows **Position N in the merge queue** and a **Remove from queue**
22 button.
23
24## How an entry moves
25
26Entries are kept per target branch, in the order they joined.
27
281. **queued**: waiting for the entries ahead of it.
292. **testing**: the head of the queue. The forge merges the current tip of the branch and the
30 pull request head with the merge style the person chose. The merge is made in the object
31 store, with no working tree, and named by the temporary ref
32 `refs/forge/merge-queue/{branch}/{number}`. A CI run tests that ref.
333. **merging**: the run passed and every required check is green on the candidate. The branch
34 moves from the tip the candidate was built on to the candidate, as a compare-and-swap. The
35 pull request is then marked merged, with the usual events, notifications and post-push work.
36 The entry leaves the queue with the reason `merged`.
37
38One thing sends an entry back, and it needs no person:
39
40- **The target moved** before the swap. The candidate is built again on the new tip, and its
41 run starts again. The entry keeps its place at the head.
42
43An entry also ends early when:
44
45- **Failed** (`tests_failed`, `checks_failed`, `conflict`): the forge comments on the pull
46 request, mentions the person who queued it, and links the failing run. The entry stays in the
47 history with its reason.
48- **Removed** (`removed`): someone pressed **Remove from queue**.
49- **Removed** (`head_changed`, `closed`): the pull request's head moved, or it was closed while
50 it waited.
51- **Removed** (`blocked`, `permission`, `no_branch`): a merge check no longer passes, the person
52 who queued it can no longer write to the repo, or the branch is gone.
53
54When an entry finishes, the next one starts. Nothing polls: each step follows an event, a commit
55status on a candidate, a request that changes the queue, or a finished entry.
56
57## Testing candidates in CI
58
59A candidate is a normal commit, so the workflow in `.forge/ci.toml` reads the candidate's own
60files. The run is started with trigger `merge_queue`, on the commit of the candidate, and its
61statuses (`ci/<job>`) are written to that commit. Required checks on the branch are read from
62those statuses.
63
64To pick which workflow runs, use the `merge_queue` key in `[on]`:
65
66```toml
67[on]
68merge_queue = true
69```
70
71- With `merge_queue = true`, the workflow's jobs run for every candidate.
72- Without it, a candidate runs the `push` jobs of its target branch, the same jobs that run when
73 a commit lands there. If the workflow has no `push` trigger for the branch, the candidate has
74 no run.
75- With no workflow file at the candidate, there is no run. The queue then lands the candidate once
76 the required checks, if any, are green.
77
78See [CI]ci.md#format-reference for the other `[on]` keys.
79
80## Notes
81
82- Batching is not supported yet: one pull request is tested at a time.
83- The comments that the queue writes on a pull request are in English, whatever the viewer's
84 language.
85- The queue page is at `/{owner}/{repo}/merge-queue`. It lists the waiting entries with their
86 position, state, CI run and a remove button. `?show=history` lists the finished entries. The page
87 follows changes live.
88- A queued pull request's candidate is kept under `refs/forge/merge-queue/`. Those refs are
89 temporary; once an entry finishes, its ref is left in place until the next candidate of the
90 same pull request replaces it.