-
Notifications
You must be signed in to change notification settings - Fork 54
docs(merge-queue): document Trunk merge queue and enforcement setup #3202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Merge queue | ||
|
|
||
| PRs merge into `main` **exclusively** through the [Trunk](https://trunk.io) merge queue. The GitHub merge button and `gh pr merge` are blocked by branch rulesets — the queue is the only way in. | ||
|
|
||
| ## How to merge a PR | ||
|
|
||
| 1. Get the PR green: required checks passing (pending is fine — the queue waits), reviews approved, no conflicts. | ||
| 2. Enqueue it by commenting on the PR: | ||
|
|
||
| ``` | ||
| /trunk merge | ||
| ``` | ||
|
|
||
| (or apply the `trunk-merge-queue-submit` label). The queue tests your change merged on top of everything ahead of it, then merges it when the batch is green. | ||
|
|
||
| 3. Watch the **`Trunk Merge Queue (main)`** check run on the PR's head commit. It moves through `queued` → `in_progress` → `completed`. | ||
|
|
||
| To pull a PR back out of the queue, comment `/trunk cancel` (or remove the label). | ||
|
|
||
| ### When a queued PR fails | ||
|
|
||
| If the batch fails, Trunk kicks the PR out of the queue and the Trunk bot leaves a comment linking the workflows that failed. Fix the failure, push, and re-enqueue with `/trunk merge`. | ||
|
|
||
| Do **not** force-push a branch while it is in the queue — that removes it from the queue. | ||
|
|
||
| ## Enqueue from the command line | ||
|
|
||
| ```bash | ||
| gh pr comment <number> --body "/trunk merge" # enqueue | ||
| gh pr comment <number> --body "/trunk cancel" # cancel | ||
| ``` | ||
|
|
||
| Check the queue status without leaving the terminal: | ||
|
|
||
| ```bash | ||
| gh api repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/commits/$(gh pr view <number> --json headRefOid -q .headRefOid)/check-runs \ | ||
| --jq '.check_runs[] | select(.name | startswith("Trunk Merge Queue")) | {status, conclusion, details_url}' | ||
| ``` | ||
|
|
||
| Agents working in PostHog Code follow the [`merging-prs` skill](../.claude/skills/merging-prs/SKILL.md), which enqueues a PR and babysits it until it merges or fails. | ||
|
|
||
| --- | ||
|
|
||
| ## Admin setup (one-time) | ||
|
|
||
| Configuring the queue requires repo admin on GitHub **and** org admin in the Trunk dashboard. This section records the exact settings so the enforcement can be reproduced or audited. | ||
|
|
||
| ### 1. Trunk dashboard | ||
|
|
||
| At [app.trunk.io](https://app.trunk.io) → this repo → **Merge Queue**: | ||
|
|
||
| - Enable the merge queue targeting `main`. | ||
| - Keep **draft-PR mode** (the default): Trunk opens a same-repo draft PR containing each queued batch, so the existing `pull_request`-triggered workflows run against it unchanged. No `.github/workflows/` edits are needed. | ||
| - Enable **GitHub comment commands** (`/trunk merge`, `/trunk cancel`). | ||
| - Enable the enqueue label (default name `trunk-merge-queue-submit`). | ||
|
|
||
| ### 2. GitHub Ruleset — "Merge queue enforcement" | ||
|
|
||
| Bypass permissions apply to a whole ruleset, so enforcement is split across two rulesets. Create a ruleset on `main` with: | ||
|
|
||
| - Rule: **Restrict updates** — blocks direct pushes and the merge button for everyone. | ||
| - Bypass list: the **`trunk-io` GitHub App**, mode **`Exempt`**. | ||
| - It must be `Exempt`, **not** the default `Always`. `Always` does not cover branch updates made by a GitHub App, so merges fail with a permissions error. | ||
|
|
||
| ### 3. GitHub Ruleset — "PR requirements" | ||
|
|
||
| A second ruleset on `main`, with the `trunk-io` app **not** on the bypass list (the queue relies on GitHub reporting the PR as "not ready" until these pass): | ||
|
|
||
| - Required status checks: `build`, `quality`, `unit-test`, `integration-test`, `typecheck`, `e2e`. | ||
| - `e2e` reports `skipped` when a batch touches no `packages/**` files, which still satisfies a required check. It is a live-model test — if its flakiness starts kicking otherwise-green batches out of the queue, drop it from this list (one ruleset toggle, no code change). | ||
| - Required reviews and conversation resolution as currently configured. | ||
|
|
||
| ### 4. Exclude Trunk's working branches | ||
|
|
||
| Trunk creates and deletes `trunk-temp/**` and `trunk-merge/**` branches while testing batches. Add these exclude patterns (the trailing `/*` is required for GitHub's matcher) to **any** ruleset or classic branch protection whose pattern would otherwise match them: | ||
|
|
||
| ``` | ||
| trunk-temp/**/* | ||
| trunk-merge/**/* | ||
| ``` | ||
|
|
||
| Otherwise Trunk fails with "permission denied" on its own branches. | ||
|
|
||
| ### 5. Repo settings | ||
|
|
||
| - Leave at least one merge method enabled — Trunk merges through the GitHub API, and the "Merge queue enforcement" ruleset already blocks humans. | ||
| - If GitHub's native merge queue ("Require merge queue") was ever enabled on `main`, turn it off. Only one merge-queue tool can run at a time. | ||
|
|
||
| ### 6. Smoke test | ||
|
|
||
| 1. Open a trivial PR, comment `/trunk merge`, and confirm the `Trunk Merge Queue (main)` check run appears on the head commit and the PR merges. | ||
| 2. On a second PR, confirm `gh pr merge` (and the merge button) are rejected. | ||
| 3. Record the exact check-run name observed — the app's merge-queue integration matches it by the `Trunk Merge Queue` prefix. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The referenced file
../.claude/skills/merging-prs/SKILL.md(resolved:.claude/skills/merging-prs/SKILL.md) does not exist anywhere in the repository. Any agent that encounters this doc and tries to follow the link — exactly the scenario this sentence describes — will hit a dead path and may fall back to an undefined behavior. Either create the skill file as part of this PR, or remove/update the reference until it exists.