Skip to content

Commit 18dd70c

Browse files
authored
fix(release): dispatch validation through a client-pushed target ref (#120613)
1 parent b5180b6 commit 18dd70c

2 files changed

Lines changed: 310 additions & 19 deletions

File tree

‎scripts/full-release-validation-at-sha.mjs‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ const DEFAULT_INPUTS = {
3434
function usage() {
3535
console.error(`Usage: node scripts/full-release-validation-at-sha.mjs [--sha <target-sha>] [--target-ref <canonical-release-branch-or-tag>] [--workflow-sha <trusted-main-ref>] [--keep-branch] [--dry-run] [-- -f key=value ...]
3636
37-
Creates a temporary remote branch pinned to trusted main release tooling,
38-
dispatches Full Release Validation with the target commit as its ref input,
37+
Creates temporary remote branches pinned to trusted main release tooling and
38+
the exact target commit, dispatches Full Release Validation with the target
39+
branch as its ref input,
3940
watches the parent run, verifies all child workflow head SHAs match the trusted
40-
workflow lineage through the release evidence manifest, then deletes the
41-
temporary branch by default. Exact-target and changelog-only Release SHA
41+
workflow lineage through the release evidence manifest, then deletes both
42+
temporary branches by default. --keep-branch retains both branches. Exact-target and changelog-only Release SHA
4243
evidence reuse stay enabled; pass -f reuse_evidence=false to force a fresh
4344
run. Child workflows collect independent failures by default; pass
4445
-f fail_fast=true to cancel each child after its first failed job. The release
@@ -219,6 +220,35 @@ function resolveSha(requestedSha) {
219220
return run("git", ["rev-parse", "--verify", `${rev}^{commit}`], { dryRun: false });
220221
}
221222

223+
function fetchTargetRef(targetRef) {
224+
if (!targetRef) {
225+
return;
226+
}
227+
const sourceRef = RELEASE_BRANCH_PATTERN.test(targetRef)
228+
? `refs/heads/${targetRef}`
229+
: `refs/tags/${targetRef}`;
230+
run("git", ["fetch", "--no-tags", "origin", sourceRef], {
231+
stdio: "inherit",
232+
});
233+
}
234+
235+
function resolveTargetSha(requestedSha, targetRef) {
236+
fetchTargetRef(targetRef);
237+
const revision = requestedSha || "HEAD";
238+
const resolved = runStatus("git", ["rev-parse", "--verify", `${revision}^{commit}`], {
239+
stdio: ["ignore", "pipe", "ignore"],
240+
});
241+
const resolvedSha = typeof resolved.stdout === "string" ? resolved.stdout.trim() : "";
242+
if (resolved.status !== 0 || !resolvedSha) {
243+
throw new Error(
244+
targetRef
245+
? `Target SHA ${revision} is not available locally after fetching ${targetRef}`
246+
: `Target SHA ${revision} is not available locally; pass --target-ref so it can be fetched by name`,
247+
);
248+
}
249+
return resolvedSha;
250+
}
251+
222252
export function releaseProfileForTarget(
223253
targetSha,
224254
readPackageJson = (sha) => run("git", ["show", `${sha}:package.json`]),
@@ -408,7 +438,7 @@ function verifyReleaseEvidence(parentRunId, workflowSha) {
408438

409439
function main() {
410440
const args = parseArgs(process.argv.slice(2));
411-
const targetSha = resolveSha(args.sha);
441+
const targetSha = resolveTargetSha(args.sha, args.targetRef);
412442
args.inputs.release_profile ??= releaseProfileForTarget(targetSha);
413443
args.inputs.allow_unreleased_changelog ??= args.targetRef ? "false" : "true";
414444
const targetContextRef = verifyTargetRef(args.targetRef, targetSha);
@@ -417,25 +447,32 @@ function main() {
417447
const shortSha = workflowSha.slice(0, 12);
418448
const branch = `release-ci/${shortSha}-${Date.now()}`;
419449
const remoteBranchRef = `refs/heads/${branch}`;
450+
const targetBranch = `validation/target-${targetSha.slice(0, 12)}-${Date.now()}`;
451+
const remoteTargetBranchRef = `refs/heads/${targetBranch}`;
420452
const dispatchInputs = {
421-
ref: targetSha,
453+
ref: targetBranch,
422454
...(targetContextRef !== targetSha ? { target_context_ref: targetContextRef } : {}),
423455
...args.inputs,
424456
};
425457

426458
console.log(`Target SHA: ${targetSha}`);
427459
console.log(`Trusted workflow SHA: ${workflowSha}`);
460+
console.log(`Temporary target ref: ${targetBranch}`);
428461
console.log(`Temporary workflow ref: ${branch}`);
429462

430-
run("git", ["push", "origin", `${workflowSha}:${remoteBranchRef}`], {
431-
dryRun: args.dryRun,
432-
stdio: "inherit",
433-
});
434-
435463
let parentRunId;
436464
let parentConclusion = "";
437465
let evidenceVerified = false;
438466
try {
467+
run("git", ["push", "origin", `${targetSha}:${remoteTargetBranchRef}`], {
468+
dryRun: args.dryRun,
469+
stdio: "inherit",
470+
});
471+
run("git", ["push", "origin", `${workflowSha}:${remoteBranchRef}`], {
472+
dryRun: args.dryRun,
473+
stdio: "inherit",
474+
});
475+
439476
const dispatchArgs = ["workflow", "run", WORKFLOW, "--ref", branch];
440477
for (const [key, value] of Object.entries(dispatchInputs)) {
441478
dispatchArgs.push("-f", `${key}=${value}`);
@@ -481,15 +518,16 @@ function main() {
481518
evidenceVerified,
482519
})
483520
) {
484-
run("git", ["push", "origin", `:${remoteBranchRef}`], {
521+
run("git", ["push", "origin", `:${remoteBranchRef}`, `:${remoteTargetBranchRef}`], {
485522
dryRun: args.dryRun,
486523
stdio: "inherit",
487524
});
488525
} else {
526+
const keptRefs = `${remoteBranchRef} and ${remoteTargetBranchRef}`;
489527
console.warn(
490528
args.keepBranch
491-
? `Kept ${remoteBranchRef}`
492-
: `Kept ${remoteBranchRef}: ${
529+
? `Kept ${keptRefs}`
530+
: `Kept ${keptRefs}: ${
493531
parentConclusion === "success"
494532
? "release evidence was not verified"
495533
: `parent concluded ${parentConclusion || "without a conclusion"}`
@@ -503,7 +541,10 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
503541
try {
504542
main();
505543
} catch (error) {
506-
console.error(error instanceof Error ? error.message : String(error));
507-
process.exit(1);
544+
console.error(
545+
`[full-release-validation] FAILED: ${error instanceof Error ? error.message : String(error)}`,
546+
);
547+
console.error("[full-release-validation] FAILED (exit 1)");
548+
process.exitCode = 1;
508549
}
509550
}

0 commit comments

Comments
 (0)