fix(ci): bind timing evidence to its workflow attempt (#14080)

Co-authored-by: ShuaixinHuang <ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
ShuaixinHuangandShuaixinHuang authored and GitHub committed 2026-11-23 09:20:55 -05:00
1 parent 26ce3d1325
commit bc19c8d21f
3 files changed
+66 -9

No files matched your search

+8 -3
View File
@@ -46,19 +46,20 @@ export async function collectJobTimings({
}) {
const identity = validateIdentity({ repository, runId, runAttempt });
const reportPath = join(outputDirectory, "report.json");
const rawPath = join(outputDirectory, "jobs.json");
await rm(reportPath, { force: true });
await rm(rawPath, { force: true });
const endpoint = `repos/${identity.repository}/actions/runs/${identity.runId}/attempts/${identity.runAttempt}/jobs?per_page=100`;
const { stdout } = await execFileAsync(
"gh",
["api", "--paginate", "--slurp", endpoint],
{ env, encoding: "utf8", maxBuffer: MAX_BUFFER, timeout: timeoutMs },
);
const rawPath = join(outputDirectory, "jobs.json");
await mkdir(outputDirectory, { recursive: true });
await writeFile(rawPath, stdout, "utf8");
const pages = parsePages(stdout);
const jobs = pages.flatMap(({ jobs: pageJobs }, index) =>
validateJobs(pageJobs, index),
validateJobs(pageJobs, index, identity),
);
if (
pages.some(
@@ -125,7 +126,7 @@ function parsePages(stdout) {
return pages;
}
function validateJobs(jobs, pageIndex) {
function validateJobs(jobs, pageIndex, { runId, runAttempt }) {
return jobs.map((job, jobIndex) => {
if (
typeof job !== "object" ||
@@ -138,6 +139,10 @@ function validateJobs(jobs, pageIndex) {
throw new Error(
`GitHub jobs API page ${String(pageIndex + 1)} job ${String(jobIndex + 1)} is malformed`,
);
if (job.run_id !== runId || job.run_attempt !== runAttempt)
throw new Error(
`GitHub jobs API page ${String(pageIndex + 1)} job ${String(jobIndex + 1)} belongs to a different workflow run or attempt`,
);
return job;
});
}