fix(ci): keep static diagnostics for each workflow attempt (#14360)

* fix(ci): keep static diagnostics for each workflow attempt

* test(ci): verify artifact retrieval for static-check retries

* docs(ci): explain static diagnostic names on reruns

---------

Co-authored-by: ShuaixinHuang <ShuaixinHuang@users.noreply.github.com>
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-24 11:48:28 -05:00
1 parent a19b3dbaab
commit d15068e2b4
6 files changed
+81 -51

No files matched your search

+2 -2
View File
@@ -262,7 +262,7 @@ jobs:
if: always() && needs.changes.outputs.code == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: static-check-reports
name: ${{ github.run_attempt == 1 && 'static-check-reports' || format('static-check-reports-attempt-{0}', github.run_attempt) }}
path: .cache/static-checks/
include-hidden-files: true
if-no-files-found: ignore
@@ -329,7 +329,7 @@ jobs:
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: static-deep-check-reports
name: ${{ github.run_attempt == 1 && 'static-deep-check-reports' || format('static-deep-check-reports-attempt-{0}', github.run_attempt) }}
path: .cache/static-checks/
include-hidden-files: true
if-no-files-found: ignore
+2 -1
View File
@@ -166,7 +166,8 @@ no compiled-runtime prerequisite, not a fixed time budget.
duplication statistics. Complete reports remain in `.cache/static-checks/`.
The fast gate uploads them as `static-check-reports`. Full qualification
uploads duplication diagnostics from the deep job as
`static-deep-check-reports`, including after that gate fails.
`static-deep-check-reports`, including after that gate fails. On reruns, both
artifact names end in `-attempt-N`, where `N` is the workflow run attempt.
Task-graph recording runs `check:ci:fast:tasks` and `check:ci:deep:tasks`
without the artifacts lock, so it can record hashes while `check:pr` or
`check:test` already holds that lock. The CI jobs still run the locked
+5 -2
View File
@@ -150,7 +150,8 @@ export function selectStaticCheckArtifact(
runAttempt,
name = STATIC_EVIDENCE_ARTIFACTS["Static checks"],
) {
if (runAttempt !== 1) return null;
if (!Number.isSafeInteger(runAttempt) || runAttempt < 1) return null;
const attemptName = runAttempt === 1 ? name : `${name}-attempt-${runAttempt}`;
if (
!Array.isArray(page?.artifacts) ||
!Number.isSafeInteger(page.total_count) ||
@@ -158,7 +159,9 @@ export function selectStaticCheckArtifact(
page.artifacts.length >= 100
)
return null;
const matches = page.artifacts.filter((artifact) => artifact.name === name);
const matches = page.artifacts.filter(
(artifact) => artifact.name === attemptName,
);
if (matches.length !== 1) return null;
const [artifact] = matches;
if (
-1
View File
@@ -367,7 +367,6 @@ export function createGitHubApi({
async getStaticEvidence(repository, run, job) {
const artifactName = STATIC_EVIDENCE_ARTIFACTS[job.name];
if (!artifactName) return null;
if (run.run_attempt !== 1) return null;
const page = await request(
`repos/${repository}/actions/runs/${positiveId(run.id)}/artifacts?per_page=100&page=1`,
);
@@ -507,6 +507,11 @@ it("uses static artifacts only when listing is complete, unique, and tied to thi
2,
),
).toBeNull();
const retry = { ...artifact, id: 14, name: "static-check-reports-attempt-2" };
const history = { total_count: 2, artifacts: [artifact, retry] };
expect(selectStaticCheckArtifact(history, runRecord, 1)).toBe(artifact);
expect(selectStaticCheckArtifact(history, runRecord, 2)).toBe(retry);
expect(selectStaticCheckArtifact(history, runRecord, 3)).toBeNull();
const deep = { ...artifact, id: 13, name: "static-deep-check-reports" };
expect(
selectStaticCheckArtifact(
@@ -533,51 +538,66 @@ it("uses static artifacts only when listing is complete, unique, and tied to thi
).toBeNull();
});
it("loads each static gate from its own artifact", async () => {
const downloads: string[] = [];
const api = createGitHubApi({
token: "fixture-token",
fetchImpl: async (url) => {
downloads.push(String(url));
throw new Error("stop-before-download");
},
apiRequest: async () => ({
total_count: 2,
artifacts: [
it.each([
[1, ""],
[2, "-attempt-2"],
])(
"loads each static gate from its own artifact on attempt %i",
async (attempt, suffix) => {
const downloads: string[] = [];
const api = createGitHubApi({
token: "fixture-token",
fetchImpl: async (url) => {
downloads.push(String(url));
throw new Error("stop-before-download");
},
apiRequest: async () => ({
total_count: 2,
artifacts: [
{
id: 1,
name: `static-check-reports${suffix}`,
expired: false,
workflow_run: { id: 10, head_sha: sha("a") },
},
{
id: 2,
name: `static-deep-check-reports${suffix}`,
expired: false,
workflow_run: { id: 10, head_sha: sha("a") },
},
],
}),
});
const runRecord = { id: 10, run_attempt: attempt, head_sha: sha("a") };
await expect(
api.getStaticEvidence("owner/rea", runRecord, {
name: "Deep static checks",
}),
).rejects.toThrow("stop-before-download");
await expect(
api.getStaticEvidence("owner/rea", runRecord, { name: "Static checks" }),
).rejects.toThrow("stop-before-download");
expect(
await api.getStaticEvidence("owner/rea", runRecord, {
name: "Test shard (1)",
}),
).toBeNull();
await expect(
api.getStaticEvidence(
"owner/rea",
{ ...runRecord, run_attempt: 3 },
{
id: 1,
name: "static-check-reports",
expired: false,
workflow_run: { id: 10, head_sha: sha("a") },
name: "Static checks",
},
{
id: 2,
name: "static-deep-check-reports",
expired: false,
workflow_run: { id: 10, head_sha: sha("a") },
},
],
}),
});
const runRecord = { id: 10, run_attempt: 1, head_sha: sha("a") };
await expect(
api.getStaticEvidence("owner/rea", runRecord, {
name: "Deep static checks",
}),
).rejects.toThrow("stop-before-download");
await expect(
api.getStaticEvidence("owner/rea", runRecord, { name: "Static checks" }),
).rejects.toThrow("stop-before-download");
expect(
await api.getStaticEvidence("owner/rea", runRecord, {
name: "Test shard (1)",
}),
).toBeNull();
expect(downloads).toEqual([
"https://api.github.com/repos/owner/rea/actions/artifacts/2/zip",
"https://api.github.com/repos/owner/rea/actions/artifacts/1/zip",
]);
});
),
).resolves.toBeNull();
expect(downloads).toEqual([
"https://api.github.com/repos/owner/rea/actions/artifacts/2/zip",
"https://api.github.com/repos/owner/rea/actions/artifacts/1/zip",
]);
},
);
it("rejects artifact redirects that could send the bearer token to a non-HTTPS host", async () => {
const calls: string[] = [];
+9 -2
View File
@@ -216,9 +216,16 @@ it("starts source feedback before build and requires both groups without waiving
env: { CI_STATIC_CONTEXT_SCRIPT: "check:ci:deep:tasks" },
});
const deepUpload = jobs["static-deep"]?.steps?.find(
(step) => step.with?.name === "static-deep-check-reports",
(step) => step.name === "Upload complete deep static diagnostics",
);
expect(deepUpload?.if).toBe("always()");
expect(deepUpload?.with?.name).toContain(
"static-deep-check-reports-attempt-{0}",
);
const fastUpload = jobs.static?.steps?.find(
(step) => step.name === "Upload complete static diagnostics",
);
expect(fastUpload?.with?.name).toContain("static-check-reports-attempt-{0}");
expect(deepUpload?.with).toMatchObject({
path: ".cache/static-checks/",
"if-no-files-found": "ignore",
@@ -232,7 +239,7 @@ it("starts source feedback before build and requires both groups without waiving
(step) => step.run === "npm run check:ci:deep",
);
const uploadIndex = deepSteps.findIndex(
(step) => step.with?.name === "static-deep-check-reports",
(step) => step.name === "Upload complete deep static diagnostics",
);
expect(contextIndex).toBeGreaterThanOrEqual(0);
expect(checkIndex).toBeGreaterThan(contextIndex);