diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 649d0ce9d7c..17e6ed5d746 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/docs/development/testing.md b/docs/development/testing.md index b993e0c7a0a..b5fcf27d733 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -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 diff --git a/scripts/ci/artifacts.mjs b/scripts/ci/artifacts.mjs index 6e7e6822ab7..2fb15f1541c 100644 --- a/scripts/ci/artifacts.mjs +++ b/scripts/ci/artifacts.mjs @@ -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 ( diff --git a/scripts/ci/failure-report.mjs b/scripts/ci/failure-report.mjs index 09d2977d286..011a124ea53 100644 --- a/scripts/ci/failure-report.mjs +++ b/scripts/ci/failure-report.mjs @@ -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`, ); diff --git a/tests/boundary/filesystem/ciFailureReport.test.ts b/tests/boundary/filesystem/ciFailureReport.test.ts index f2487e1e9f3..4ab1cf95098 100644 --- a/tests/boundary/filesystem/ciFailureReport.test.ts +++ b/tests/boundary/filesystem/ciFailureReport.test.ts @@ -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[] = []; diff --git a/tests/boundary/filesystem/ciFeedback.test.ts b/tests/boundary/filesystem/ciFeedback.test.ts index 2674d1d9243..3a8db710c36 100644 --- a/tests/boundary/filesystem/ciFeedback.test.ts +++ b/tests/boundary/filesystem/ciFeedback.test.ts @@ -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);