Skip to content

Commit 76b1f6f

Browse files
Merge remote-tracking branch 'origin/main' into pr-134468-prep
2 parents 329c184 + 09f9cbd commit 76b1f6f

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎scripts/ci-run-timings.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,21 @@ function listRecentSuccessfulCiRuns(limit) {
301301
"list",
302302
"--branch",
303303
"main",
304+
"--event",
305+
"push",
304306
"--workflow",
305307
"CI",
306308
"--limit",
307309
String(Math.max(limit * 4, limit)),
308310
"--json",
309-
"databaseId,headSha,status,conclusion",
311+
"databaseId,headSha,event,status,conclusion",
310312
],
311313
{ encoding: "utf8" },
312314
);
313315
return JSON.parse(raw)
314-
.filter((run) => run.status === "completed" && run.conclusion === "success")
316+
.filter(
317+
(run) => run.event === "push" && run.status === "completed" && run.conclusion === "success",
318+
)
315319
.slice(0, limit);
316320
}
317321

‎test/scripts/ci-run-timings.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,59 @@ if (endpoint.includes("actions/workflows/ci.yml/runs?")) {
509509
rmSync(fixtureDir, { force: true, recursive: true });
510510
}
511511
});
512+
it("excludes manual, failed, and unfinished runs from recent main timings", () => {
513+
const fixtureDir = mkdtempSync(path.join(tmpdir(), "openclaw-ci-timings-recent-"));
514+
const fakeGhPath = path.join(fixtureDir, "gh");
515+
const callsPath = path.join(fixtureDir, "calls.jsonl");
516+
writeFileSync(
517+
fakeGhPath,
518+
`#!/usr/bin/env node
519+
const { appendFileSync } = require("node:fs");
520+
const args = process.argv.slice(2);
521+
appendFileSync(process.env.FIXTURE_CALLS_PATH, JSON.stringify(args) + "\\n");
522+
if (args[0] === "run" && args[1] === "list") {
523+
console.log(JSON.stringify([
524+
{ databaseId: 201, event: "workflow_dispatch", headSha: "manual", status: "completed", conclusion: "success" },
525+
{ databaseId: 202, event: "push", headSha: "failed", status: "completed", conclusion: "failure" },
526+
{ databaseId: 203, event: "push", headSha: "running", status: "in_progress", conclusion: "" },
527+
{ databaseId: 204, event: "push", headSha: "first", status: "completed", conclusion: "success" },
528+
{ databaseId: 205, event: "push", headSha: "second", status: "completed", conclusion: "success" }
529+
]));
530+
} else if (args[0] === "run" && args[1] === "view") {
531+
console.log(JSON.stringify({ status: "completed", conclusion: "success", createdAt: "2026-08-31T00:00:00Z", updatedAt: "2026-08-31T00:01:00Z" }));
532+
} else if (args[0] === "api" && args.some((arg) => arg.includes("/jobs?"))) {
533+
console.log(JSON.stringify({ total_count: 1, jobs: [{ id: 1, name: "checks", status: "completed", conclusion: "success", started_at: "2026-08-31T00:00:10Z", completed_at: "2026-08-31T00:00:40Z" }] }));
534+
} else {
535+
process.exit(2);
536+
}
537+
`,
538+
);
539+
chmodSync(fakeGhPath, 0o755);
540+
try {
541+
const result = spawnSync(process.execPath, ["scripts/ci-run-timings.mjs", "--recent", "2"], {
542+
cwd: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."),
543+
encoding: "utf8",
544+
env: {
545+
...process.env,
546+
GH_TOKEN: "fixture-token",
547+
OPENCLAW_GH_BIN: fakeGhPath,
548+
FIXTURE_CALLS_PATH: callsPath,
549+
},
550+
});
551+
expect(result.status, result.stderr).toBe(0);
552+
expect(result.stdout.match(/CI run \d+/gu)).toEqual(["CI run 204", "CI run 205"]);
553+
const calls: string[][] = readFileSync(callsPath, "utf8")
554+
.trim()
555+
.split("\n")
556+
.map((line) => JSON.parse(line));
557+
expect(calls[0]?.slice(calls[0].indexOf("--event"), calls[0].indexOf("--event") + 2)).toEqual(
558+
["--event", "push"],
559+
);
560+
expect(
561+
calls.filter((args) => args[0] === "run" && args[1] === "view").map((args) => args[2]),
562+
).toEqual(["204", "205"]);
563+
} finally {
564+
rmSync(fixtureDir, { force: true, recursive: true });
565+
}
566+
});
512567
});

0 commit comments

Comments
 (0)