feat(scripts): check PRs against current main right before merging #24049
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromt3/prevent-main-test-breakagesopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -0,0 +3,21 @@3+// they merge. Main takes hundreds of merges a day, so the ruleset cannot require4+// branches to be up to date, and GitHub reports CLEAN for a PR that is far5+// behind. A PR's green CI can be days old. Most breaks on main were two changes6+// that each passed alone: a renamed type, a removed dependency, a new request7+// an older test did not stub.8+//9+// vp run pr-merge-check <pr> [<pr>...]10+//11+// Merges GitHub's main and each PR head, in order, in a temporary worktree12+// next to this checkout, then runs check:changed against that main. PR numbers13+// 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 main16+// makes the result older.17+import * as NodeChildProcess from "node:child_process";18+import * as NodeFS from "node:fs";19+import * as NodePath from "node:path";20+21+const root = NodePath.resolve(import.meta.dirname, "..");22+const prs = process.argv.slice(2);23+if (prs.length === 0 || prs.some((pr) => !/^\d+$/.test(pr))) {@@ -0,0 +29,21 @@29+// the merged worktree would run this checkout's Vitest against its own test30+// files, and two Vitest copies fail every suite.31+const env = {32+ ...process.env,33+ PATH: (process.env.PATH ?? "")34+ .split(NodePath.delimiter)35+ .filter((entry) => !entry.startsWith(`${root}${NodePath.sep}`))36+ .join(NodePath.delimiter),37+};38+39+const run = (command: string, args: ReadonlyArray<string>, cwd: string) =>40+ NodeChildProcess.spawnSync(command, args, { cwd, env, stdio: "inherit" }).status === 0;41+42+const git = (cwd: string, ...args: Array<string>) =>43+ NodeChildProcess.execFileSync("git", args, { cwd, encoding: "utf8" }).trim();44+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"];
- @@ -0,0 +23,21 @@23+if (prs.length === 0 || prs.some((pr) => !/^\d+$/.test(pr))) {24+ console.error("usage: vp run pr-merge-check <pr> [<pr>...]");25+ process.exit(1);26+}27+28+// `vp run` puts this checkout's node_modules/.bin first on PATH. Left there,29+// the merged worktree would run this checkout's Vitest against its own test30+// files, and two Vitest copies fail every suite.31+const env = {32+ ...process.env,33+ PATH: (process.env.PATH ?? "")34+ .split(NodePath.delimiter)35+ .filter((entry) => !entry.startsWith(`${root}${NodePath.sep}`))36+ .join(NodePath.delimiter),37+};38+39+const run = (command: string, args: ReadonlyArray<string>, cwd: string) =>40+ NodeChildProcess.spawnSync(command, args, { cwd, env, stdio: "inherit" }).status === 0;41+42+const git = (cwd: string, ...args: Array<string>) =>43+ NodeChildProcess.execFileSync("git", args, { cwd, encoding: "utf8" }).trim();
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — The script checks PR batches against current main in a temporary worktree, then prints pinned merge commands. Its new diagnostic suppressions require human review, and unresolved concerns question whether the checked destination and merge sequence match those commands.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).