Skip to content

Commit 865a0ad

Browse files
t3dotggclaude
andcommitted
chore(ci): pin merge-check heads and fetch from GitHub
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dce780b commit 865a0ad

3 files changed

Lines changed: 45 additions & 29 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ For authorized mobile verification, a missing or outdated native client is a bui
145145
- UI changes need before/after images. Motion or timing needs a short video.
146146
- Upload PR evidence to GitHub. Never commit PR-only screenshots or assets such as `.github/pr-assets/`.
147147
- One request is one PR. Split it only when the maintainer asks. Outside contributions follow the stricter [one problem per PR](CONTRIBUTING.md#one-problem) rule.
148-
- Right before you merge, run `vp run pr-merge-check <pr>...` with every PR you are about to merge, then merge them at once in that order. Green PR CI can be days old, and GitHub reports `CLEAN` here even when a PR is far behind `main`, so `mergeStateStatus` is not a freshness check.
148+
- Right before you merge, run `vp run pr-merge-check <pr>...` with every PR you are about to merge, then run the `gh pr merge --match-head-commit` commands it prints, at once and in that order. Green PR CI can be days old, and GitHub reports `CLEAN` here even when a PR is far behind `main`, so `mergeStateStatus` is not a freshness check.
149149
- When babysitting: call `watch_pull_request` and end your turn. T3 Code wakes you on checks, comments, or conflicts. Do not poll or sleep. Verify each bot finding against the source, fix real ones, dismiss false positives with a written reason. Stay quiet when nothing is new. Stop when the bots are green on the latest commit.
150150

151151
## Documentation

‎docs/operations/development.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ files to packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), a
160160
compares against the merge base with `origin/main`, or with a ref you pass. CI still runs the full
161161
test suites and the jobs the summary lists, so a local pass does not promise a green CI run.
162162

163-
`vp run pr-merge-check <pr>...` runs the same checks on current `origin/main` with the given PRs
164-
merged in order, in a temporary worktree. Run it right before merging, with the whole batch. The
165-
ruleset does not require branches to be up to date, because main takes too many merges a day, so a
166-
PR's green CI can be days old.
163+
`vp run pr-merge-check <pr>...` runs the same checks on GitHub's current `main` with the given PRs
164+
merged in order, in a temporary worktree. Run it right before merging, with the whole batch, then
165+
run the merge commands it prints. They are pinned to the tested heads. PR numbers are GitHub's, and
166+
with `origin` on GitCafe it fetches from the `github` remote. The ruleset does not require branches
167+
to be up to date, because main takes too many merges a day, so a PR's green CI can be days old.
167168

168169
While you iterate, run single checks:
169170

‎scripts/pr-merge-check.ts‎

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
//
99
// vp run pr-merge-check <pr> [<pr>...]
1010
//
11-
// Merges origin/main and each PR head, in order, in a temporary worktree next
12-
// to this checkout, then runs check:changed against origin/main. Pass every PR
13-
// of a batch in one run. Exit 0 means merge them now, in the same order: each
14-
// new commit on main makes the result older.
11+
// Merges GitHub's main and each PR head, in order, in a temporary worktree
12+
// next to this checkout, then runs check:changed against that main. PR numbers
13+
// are GitHub's: with `origin` on the GitCafe mirror, fetches use the `github`
14+
// remote. Pass every PR of a batch in one run. Exit 0 prints the merge commands,
15+
// pinned to the tested heads. Run them now, in order: each new commit on main
16+
// makes the result older.
1517
import * as NodeChildProcess from "node:child_process";
1618
import * as NodeFS from "node:fs";
1719
import * as NodePath from "node:path";
@@ -40,41 +42,54 @@ const run = (command: string, args: ReadonlyArray<string>, cwd: string) =>
4042
const git = (cwd: string, ...args: Array<string>) =>
4143
NodeChildProcess.execFileSync("git", args, { cwd, encoding: "utf8" }).trim();
4244

43-
git(root, "fetch", "--quiet", "origin", "+refs/heads/main:refs/remotes/origin/main");
44-
const heads = prs.map((pr) => {
45-
git(root, "fetch", "--quiet", "origin", `pull/${pr}/head`);
46-
return { pr, sha: git(root, "rev-parse", "FETCH_HEAD") };
47-
});
45+
const hasGitHubRemote =
46+
NodeChildProcess.spawnSync("git", ["remote", "get-url", "github"], { cwd: root }).status === 0;
47+
const remote = hasGitHubRemote ? "github" : "origin";
48+
// Signing can prompt or fail, which would read as a conflict.
49+
const merge = ["-c", "commit.gpgsign=false", "merge", "--quiet", "--no-ff"];
4850

51+
// The worktree has its own FETCH_HEAD, so a fetch in this checkout or in
52+
// another run cannot swap the commit under test.
4953
const dir = NodePath.resolve(root, "..", `${NodePath.basename(root)}-merge-check-${process.pid}`);
50-
git(root, "worktree", "add", "--quiet", "--detach", dir, "origin/main");
51-
// Ctrl-C reaches the running child too. Staying alive lets `finally` remove the worktree.
52-
process.on("SIGINT", () => {});
54+
git(root, "worktree", "add", "--quiet", "--detach", "--no-checkout", dir);
55+
// A terminal signal reaches the running child too. Staying alive lets
56+
// `finally` remove the worktree. SIGKILL still leaves it behind.
57+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(signal, () => {});
5358

59+
const fetchHead = (ref: string) => {
60+
git(dir, "fetch", "--quiet", remote, ref);
61+
return git(dir, "rev-parse", "FETCH_HEAD");
62+
};
63+
64+
const heads: Array<{ pr: string; sha: string }> = [];
5465
let ok = false;
5566
try {
56-
const conflict = heads.find(
57-
({ pr, sha }) =>
58-
!run("git", ["merge", "--quiet", "--no-ff", "-m", `merge-check #${pr}`, sha], dir),
59-
);
67+
const base = fetchHead("refs/heads/main");
68+
git(dir, "checkout", "--quiet", "--detach", base);
69+
const conflict = prs.find((pr) => {
70+
const sha = fetchHead(`pull/${pr}/head`);
71+
heads.push({ pr, sha });
72+
return !run("git", [...merge, "-m", `merge-check #${pr}`, sha], dir);
73+
});
6074
if (conflict) {
61-
console.error(`\npr-merge-check: #${conflict.pr} does not merge cleanly onto main.`);
75+
console.error(`\npr-merge-check: #${conflict} does not merge cleanly onto main.`);
6276
} else {
6377
// A lockfile that two PRs edited can merge as text and still not match
6478
// the manifests. The frozen install fails on that.
6579
ok =
6680
run("vp", ["i", "--frozen-lockfile", "--", "--yes"], dir) &&
67-
run("node", ["scripts/check-changed.ts", "origin/main"], dir);
81+
run("node", ["scripts/check-changed.ts", base], dir);
6882
}
6983
} finally {
7084
git(root, "worktree", "remove", "--force", dir);
7185
NodeFS.rmSync(dir, { recursive: true, force: true });
7286
}
7387

7488
const list = prs.map((pr) => `#${pr}`).join(" ");
75-
console.log(
76-
ok
77-
? `\npr-merge-check: ${list} pass on main. Merge them now, in this order.`
78-
: `\npr-merge-check: ${list} fail on main. Do not merge.`,
79-
);
80-
if (!ok) process.exit(1);
89+
if (!ok) {
90+
console.log(`\npr-merge-check: ${list} fail on main. Do not merge.`);
91+
process.exit(1);
92+
}
93+
console.log(`\npr-merge-check: ${list} pass on main. Merge them now, in this order:`);
94+
for (const { pr, sha } of heads)
95+
console.log(` gh pr merge ${pr} --squash --match-head-commit ${sha}`);

0 commit comments

Comments
 (0)