Skip to content

Commit 97c2d16

Browse files
only21milclaude
andcommitted
perf(ci): read one page of main CI runs for the transfer report baseline
The Thread Transfer Report paged through every successful main CI run (up to ten requests of 100) and then kept 20. List the exact-base runs and the newest runs with one request each instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bd6940b commit 97c2d16

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

‎.github/scripts/thread-transfer-report.cjs‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,28 @@ async function resolve({ github, context, core }) {
301301
core.setOutput("publish", "false");
302302
return;
303303
}
304-
const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRuns, {
305-
owner,
306-
repo,
307-
workflow_id: source.workflow_id,
308-
branch: pull.base.ref,
309-
event: "push",
310-
status: "success",
311-
per_page: 100,
312-
});
304+
// One page each for the exact base and the newest runs; paging through
305+
// every successful main run costs up to ten requests to keep 20.
306+
const listRuns = async (filters) => {
307+
const { data } = await github.rest.actions.listWorkflowRuns({
308+
owner,
309+
repo,
310+
workflow_id: source.workflow_id,
311+
branch: pull.base.ref,
312+
event: "push",
313+
status: "success",
314+
per_page: 20,
315+
...filters,
316+
});
317+
return data.workflow_runs;
318+
};
319+
const [baseRuns, recentRuns] = await Promise.all([
320+
listRuns({ head_sha: pull.base.sha }),
321+
listRuns({}),
322+
]);
313323
const orderedRuns = [
314-
...workflowRuns.filter((run) => run.head_sha === pull.base.sha),
315-
...workflowRuns.filter((run) => run.head_sha !== pull.base.sha),
324+
...baseRuns,
325+
...recentRuns.filter((run) => run.head_sha !== pull.base.sha),
316326
].slice(0, 20);
317327

318328
let baselineRun;

‎.github/scripts/thread-transfer-report.test.cjs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ test("validates the fixed artifact schema", () => {
5555
test("resolves a fallback PR with a redacted head repo and exact main baseline", async () => {
5656
const outputs = {};
5757
const listWorkflowRunArtifacts = () => {};
58-
const listWorkflowRuns = () => {};
58+
// The exact base run sits far past the newest page of main CI runs.
59+
const mainRuns = Array.from({ length: 1_000 }, (_, index) => ({
60+
id: 1_000 - index,
61+
head_sha: index === 900 ? "base-sha" : `main-sha-${index}`,
62+
}));
63+
const listWorkflowRuns = async ({ head_sha, per_page }) => ({
64+
data: {
65+
workflow_runs: mainRuns
66+
.filter((run) => head_sha === undefined || run.head_sha === head_sha)
67+
.slice(0, per_page),
68+
},
69+
});
5970
const listPullRequestsAssociatedWithCommit = () => {};
6071
const github = {
6172
paginate: async (method, input) => {
@@ -77,9 +88,6 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
7788
},
7889
];
7990
}
80-
if (method === listWorkflowRuns) {
81-
return [{ id: 1, head_sha: "base-sha" }];
82-
}
8391
throw new Error("unexpected pagination call");
8492
},
8593
rest: {
@@ -123,7 +131,7 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
123131
assert.equal(outputs.publish, "true");
124132
assert.equal(outputs.pull_number, "5350");
125133
assert.equal(outputs.pr_artifact, "true");
126-
assert.equal(outputs.baseline_run_id, "1");
134+
assert.equal(outputs.baseline_run_id, "100");
127135
assert.equal(outputs.baseline_matches_base, "true");
128136
});
129137

0 commit comments

Comments
 (0)