fix(ci): verify completed workflow identity for push baselines (#12423)

Co-authored-by: ShuaixinHuang <ShuaixinHuang@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-19 20:20:12 +00:00
1 parent d00c45624a
commit 762909f72c
2 files changed
+28 -2

No files matched your search

+5 -1
View File
@@ -1,5 +1,6 @@
import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { normalizeWorkflowRun } from "./workflow-run.mjs";
const repository = process.env.CI_REPOSITORY;
const branch = process.env.CI_DEFAULT_BRANCH;
@@ -56,7 +57,10 @@ if (!repository || !branch || !head || !shaPattern.test(head)) {
const base = runs.find(
(run) =>
run?.event === "push" &&
run?.conclusion === "success" &&
run.status === "completed" &&
run.conclusion === "success" &&
normalizeWorkflowRun(run).workflowPath?.file ===
".github/workflows/ci.yml" &&
run?.head_branch === branch &&
run?.head_repository?.full_name === repository &&
typeof run?.head_sha === "string" &&
@@ -815,7 +815,7 @@ it.each(["", "not-a-commit"])(
},
);
it("selects only a trusted successful ancestor from recent CI push runs", async ({
it("selects a completed CI ancestor rather than a foreign or non-terminal run", async ({
skip,
}) => {
skip(process.platform === "win32", "the fake gh is a POSIX shell script");
@@ -833,6 +833,8 @@ it("selects only a trusted successful ancestor from recent CI push runs", async
JSON.stringify({
workflow_runs: [
{
status: "completed",
path: ".github/workflows/ci.yml@refs/heads/main",
event: "push",
conclusion: "success",
head_branch: "main",
@@ -840,6 +842,26 @@ it("selects only a trusted successful ancestor from recent CI push runs", async
head_sha: foreignBase,
},
{
status: "in_progress",
path: ".github/workflows/ci.yml@refs/heads/main",
event: "push",
conclusion: "success",
head_branch: "main",
head_repository: { full_name: "owner/repo" },
head_sha: foreignBase,
},
{
status: "completed",
path: ".github/workflows/release.yml@refs/heads/main",
event: "push",
conclusion: "success",
head_branch: "main",
head_repository: { full_name: "owner/repo" },
head_sha: foreignBase,
},
{
status: "completed",
path: ".github/workflows/ci.yml@refs/heads/main",
event: "push",
conclusion: "success",
head_branch: "main",