diff --git a/scripts/ci/baseline.mjs b/scripts/ci/baseline.mjs index 171bd7dd36..5e48c842fb 100644 --- a/scripts/ci/baseline.mjs +++ b/scripts/ci/baseline.mjs @@ -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" && diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index 4a83e72174..520a555288 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -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",