fix(ci): stamp BUILD_SHA before the release-green pack gate validates

check:pack-artifact assembles dist/ through build:cli, which never writes
dist/BUILD_SHA (only build:release does). #12959 pointed the provenance ref at
HEAD, but the #10427 guard still stops at 'dist/BUILD_SHA is missing' before it
ever reaches the ancestry check — reproduced on tip + #13635 + #13436, the first
tree whose Turbopack build compiles.

ci.yml sequences build -> stamp -> validate; the validator now does the same in
both entry points, keeping PACK_GATE_ENV for the validate step. The guard is
unchanged: an unstamped dist/ or one built from another commit still fails.
On that tree the stamped gate passes: 'BUILD_SHA 5cb3ae5d9 is on the release line'.

Refs #12732
This commit is contained in:
diegosouzapw
2026-09-14 19:07:00 -03:00
parent 6b08790274
commit 2ef073f513
3 changed files with 64 additions and 7 deletions

View File

@@ -461,6 +461,37 @@ async function runAsync(cmd, cmdArgs, opts = {}) {
}
}
/**
* Package-artifact gate, run the way ci.yml's pack job runs it (#10427).
*
* `check:pack-artifact` assembles dist/ through `build:cli` when staging is missing, and
* `build:cli` never writes dist/BUILD_SHA — only `build:release` does. Pointing the ref at
* HEAD (PACK_GATE_ENV) is not enough on its own: the guard still stops at "dist/BUILD_SHA is
* missing". ci.yml builds, stamps, then validates; mirror that order here. The guard is not
* relaxed: an unstamped dist/ or one built from another commit still fails.
*/
async function runPackArtifactGate(timeoutMs) {
const deadline = Date.now() + timeoutMs;
const steps = [
{ cmd: npmCmd, args: ["run", "build:cli"] },
{ cmd: process.execPath, args: ["scripts/build/write-build-sha.mjs"] },
{
cmd: npmCmd,
args: ["run", "check:pack-artifact"],
env: PACK_GATE_ENV,
},
];
let out = "";
for (const step of steps) {
const remaining = deadline - Date.now();
if (remaining <= 0) return classifyRunError({ killed: true, signal: "SIGTERM" }, timeoutMs);
const result = await runAsync(step.cmd, step.args, { env: step.env, timeout: remaining });
out += result.out;
if (result.code !== 0) return { code: result.code, out };
}
return { code: 0, out };
}
async function main() {
const args = new Set(process.argv.slice(2));
const JSON_OUT = args.has("--json");
@@ -713,14 +744,15 @@ async function main() {
slow.push({
id: "pack-artifact",
label: "Package artifact (npm pack policy)",
args: ["run", "check:pack-artifact"],
env: PACK_GATE_ENV,
run: runPackArtifactGate,
timeout: 20 * 60 * 1000,
});
}
slow.forEach((g) => announce(`${g.label} [parallel]`));
const slowResults = await Promise.all(
slow.map((g) => runAsync(npmCmd, g.args, { timeout: g.timeout, env: g.env }))
slow.map((g) =>
g.run ? g.run(g.timeout) : runAsync(npmCmd, g.args, { timeout: g.timeout, env: g.env })
)
);
slow.forEach((g, i) => {
const { code, out } = slowResults[i];
@@ -770,10 +802,7 @@ async function main() {
}
} else if (WITH_BUILD) {
// --with-build without the suites (--quick): still verify the package artifact.
const { code, out } = await runAsync(npmCmd, ["run", "check:pack-artifact"], {
env: PACK_GATE_ENV,
timeout: 20 * 60 * 1000,
});
const { code, out } = await runPackArtifactGate(20 * 60 * 1000);
saveGateLog("pack-artifact", out);
record({
id: "pack-artifact",