Skip to content
TypeScript

perf(ci): thread transfer report stops paging all main CI runs (#23633)

Victor Vogelfc1d604e3931
diff --git a/.github/scripts/thread-transfer-report.cjs b/.github/scripts/thread-transfer-report.cjs
index ca57769ed49..09b25131e4c 100644
--- a/.github/scripts/thread-transfer-report.cjs
+++ b/.github/scripts/thread-transfer-report.cjs
@@ -300,18 +300,28 @@ async function resolve({ github, context, core }) {
core.setOutput("publish", "false");
return;
}
- const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRuns, {
- owner,
- repo,
- workflow_id: source.workflow_id,
- branch: pull.base.ref,
- event: "push",
- status: "success",
- per_page: 100,
- });
+ // One page each for the exact base and the newest runs; paging through
+ // every successful main run costs up to ten requests to keep 20.
+ const listRuns = async (filters) => {
+ const { data } = await github.rest.actions.listWorkflowRuns({
+ owner,
+ repo,
+ workflow_id: source.workflow_id,
+ branch: pull.base.ref,
+ event: "push",
+ status: "success",
+ per_page: 20,
+ ...filters,
+ });
+ return data.workflow_runs;
+ };
+ const [baseRuns, recentRuns] = await Promise.all([
+ listRuns({ head_sha: pull.base.sha }),
+ listRuns({}),
+ ]);
const orderedRuns = [
- ...workflowRuns.filter((run) => run.head_sha === pull.base.sha),
- ...workflowRuns.filter((run) => run.head_sha !== pull.base.sha),
+ ...baseRuns,
+ ...recentRuns.filter((run) => run.head_sha !== pull.base.sha),
].slice(0, 20);
let baselineRun;
diff --git a/.github/scripts/thread-transfer-report.test.cjs b/.github/scripts/thread-transfer-report.test.cjs
index 753c3eb7590..8c4595ccf0c 100644
--- a/.github/scripts/thread-transfer-report.test.cjs
+++ b/.github/scripts/thread-transfer-report.test.cjs
@@ -55,7 +55,18 @@ test("validates the fixed artifact schema", () => {
test("resolves a fallback PR with a redacted head repo and exact main baseline", async () => {
const outputs = {};
const listWorkflowRunArtifacts = () => {};
- const listWorkflowRuns = () => {};
+ // The exact base run sits far past the newest page of main CI runs.
+ const mainRuns = Array.from({ length: 1_000 }, (_, index) => ({
+ id: 1_000 - index,
+ head_sha: index === 900 ? "base-sha" : `main-sha-${index}`,
+ }));
+ const listWorkflowRuns = async ({ head_sha, per_page }) => ({
+ data: {
+ workflow_runs: mainRuns
+ .filter((run) => head_sha === undefined || run.head_sha === head_sha)
+ .slice(0, per_page),
+ },
+ });
const listPullRequestsAssociatedWithCommit = () => {};
const github = {
paginate: async (method, input) => {
@@ -77,9 +88,6 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
},
];
}
- if (method === listWorkflowRuns) {
- return [{ id: 1, head_sha: "base-sha" }];
- }
throw new Error("unexpected pagination call");
},
rest: {
@@ -123,7 +131,7 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
assert.equal(outputs.publish, "true");
assert.equal(outputs.pull_number, "5350");
assert.equal(outputs.pr_artifact, "true");
- assert.equal(outputs.baseline_run_id, "1");
+ assert.equal(outputs.baseline_run_id, "100");
assert.equal(outputs.baseline_matches_base, "true");
});