Skip to content

Commit cbef131

Browse files
committed
fix(ci): accept exact release gate fallback
1 parent 6e40e7e commit cbef131

2 files changed

Lines changed: 86 additions & 6 deletions

File tree

‎scripts/verify-pr-hosted-gates.mjs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const SCHEDULED_HOSTED_WORKFLOWS = [
1010
"Blacksmith Build Artifacts Testbox",
1111
"Workflow Sanity",
1212
];
13+
const CI_WORKFLOW_PATH = ".github/workflows/ci.yml";
1314

1415
function readOptionValue(argv, index, optionName) {
1516
const value = argv[index + 1];
@@ -64,19 +65,22 @@ function formatObservedRuns(runs) {
6465

6566
function isReleaseGateCiRun(run, sha) {
6667
return (
67-
run?.name === "CI" &&
6868
run?.event === "workflow_dispatch" &&
6969
run?.head_sha === sha &&
70+
String(run?.path ?? "").split("@", 1)[0] === CI_WORKFLOW_PATH &&
7071
run?.display_title === `CI release gate ${sha}`
7172
);
7273
}
7374

7475
function matchingAuthoritativeRuns(runs, workflowName, sha) {
7576
return runs.filter((run) => {
76-
if (run?.name !== workflowName || run?.head_sha !== sha) {
77+
if (run?.head_sha !== sha) {
7778
return false;
7879
}
79-
return run.event === "pull_request" || (workflowName === "CI" && isReleaseGateCiRun(run, sha));
80+
if (run?.event === "pull_request") {
81+
return run.name === workflowName;
82+
}
83+
return workflowName === "CI" && isReleaseGateCiRun(run, sha);
8084
});
8185
}
8286

@@ -86,9 +90,24 @@ function latestRun(runs) {
8690
)[0];
8791
}
8892

93+
function preferredCiRun(runs) {
94+
const scheduledRuns = runs.filter((run) => run.event === "pull_request");
95+
const failedScheduledRun = scheduledRuns.find(
96+
(run) => run.status === "completed" && run.conclusion !== "success",
97+
);
98+
if (failedScheduledRun) {
99+
return failedScheduledRun;
100+
}
101+
const latestScheduledRun = latestRun(scheduledRuns);
102+
if (latestScheduledRun?.status === "completed") {
103+
return latestScheduledRun;
104+
}
105+
return latestRun(runs.filter((run) => run.event === "workflow_dispatch")) ?? latestScheduledRun;
106+
}
107+
89108
function successfulRunOrThrow(runs, workflowName, sha) {
90109
const matchingRuns = matchingAuthoritativeRuns(runs, workflowName, sha);
91-
const run = latestRun(matchingRuns);
110+
const run = workflowName === "CI" ? preferredCiRun(matchingRuns) : latestRun(matchingRuns);
92111
if (!run || run.status !== "completed" || run.conclusion !== "success") {
93112
throw new Error(
94113
`Missing successful exact-head ${workflowName} workflow for ${sha}. Observed: ${formatObservedRuns(matchingRuns)}`,

‎test/scripts/verify-pr-hosted-gates.test.ts‎

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function successfulRun(name: string, id: number, updatedAt: string) {
1616
status: "completed",
1717
conclusion: "success",
1818
head_sha: sha,
19+
path: ".github/workflows/ci.yml",
1920
created_at: "2026-06-17T10:46:24Z",
2021
updated_at: updatedAt,
2122
html_url: `https://github.com/openclaw/openclaw/actions/runs/${id}`,
@@ -79,30 +80,74 @@ describe("verify-pr-hosted-gates", () => {
7980
});
8081

8182
it("accepts the explicit exact-SHA manual CI release gate", () => {
83+
expect(
84+
collectHostedGateEvidence({
85+
sha,
86+
workflowRuns: [
87+
{
88+
...successfulRun(`CI release gate ${sha}`, 1, "2026-06-17T10:47:00Z"),
89+
event: "workflow_dispatch",
90+
path: ".github/workflows/ci.yml@refs/heads/release-controls",
91+
display_title: `CI release gate ${sha}`,
92+
},
93+
],
94+
}),
95+
).toEqual({
96+
headSha: sha,
97+
workflows: [expect.objectContaining({ name: `CI release gate ${sha}`, id: 1 })],
98+
});
99+
});
100+
101+
it("prefers the exact release-gate fallback while scheduled CI remains queued", () => {
82102
expect(
83103
collectHostedGateEvidence({
84104
sha,
85105
workflowRuns: [
86106
{
87107
...successfulRun("CI", 1, "2026-06-17T10:47:00Z"),
108+
status: "queued",
109+
conclusion: null,
110+
updated_at: "2026-06-17T10:50:00Z",
111+
},
112+
{
113+
...successfulRun(`CI release gate ${sha}`, 2, "2026-06-17T10:49:00Z"),
88114
event: "workflow_dispatch",
89115
display_title: `CI release gate ${sha}`,
90116
},
91117
],
92118
}),
93119
).toEqual({
94120
headSha: sha,
95-
workflows: [expect.objectContaining({ name: "CI", id: 1 })],
121+
workflows: [expect.objectContaining({ name: `CI release gate ${sha}`, id: 2 })],
96122
});
97123
});
98124

125+
it("rejects a completed scheduled CI failure even when a fallback passed", () => {
126+
expect(() =>
127+
collectHostedGateEvidence({
128+
sha,
129+
workflowRuns: [
130+
{
131+
...successfulRun("CI", 1, "2026-06-17T10:50:00Z"),
132+
conclusion: "failure",
133+
},
134+
{
135+
...successfulRun(`CI release gate ${sha}`, 2, "2026-06-17T10:49:00Z"),
136+
event: "workflow_dispatch",
137+
display_title: `CI release gate ${sha}`,
138+
},
139+
],
140+
}),
141+
).toThrow("Missing successful exact-head CI workflow");
142+
});
143+
99144
it("rejects an unmarked manual CI run", () => {
100145
expect(() =>
101146
collectHostedGateEvidence({
102147
sha,
103148
workflowRuns: [
104149
{
105-
...successfulRun("CI", 1, "2026-06-17T10:47:00Z"),
150+
...successfulRun(`CI release gate ${sha}`, 1, "2026-06-17T10:47:00Z"),
106151
event: "workflow_dispatch",
107152
display_title: "CI",
108153
},
@@ -111,6 +156,22 @@ describe("verify-pr-hosted-gates", () => {
111156
).toThrow("Missing successful exact-head CI workflow");
112157
});
113158

159+
it("rejects a manual release-gate title from another workflow", () => {
160+
expect(() =>
161+
collectHostedGateEvidence({
162+
sha,
163+
workflowRuns: [
164+
{
165+
...successfulRun(`CI release gate ${sha}`, 1, "2026-06-17T10:47:00Z"),
166+
event: "workflow_dispatch",
167+
path: ".github/workflows/something-else.yml",
168+
display_title: `CI release gate ${sha}`,
169+
},
170+
],
171+
}),
172+
).toThrow("Missing successful exact-head CI workflow");
173+
});
174+
114175
it("requires CI for docs unless the head changes only CHANGELOG.md", () => {
115176
expect(() => collectHostedGateEvidence({ sha, workflowRuns: [] })).toThrow(
116177
"Missing successful exact-head CI workflow",

0 commit comments

Comments
 (0)