From 72c96d31bc6406d50c92335c439ad63ed5cb219b Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 5 Nov 2026 18:51:51 -0800 Subject: [PATCH] fix: make diagnostic artifact names unique per step Every job in a run uploaded capa_artifacts-, so only the first upload succeeded. Add the run attempt, job and step IDs. Co-Authored-By: Claude Opus 5.5 --- src/instrumentation.ts | 18 +++++++++++++++++- test/instrumentation.test.ts | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 2c38dcd..5e64434 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -41,10 +41,26 @@ export class Artifacts { ) {} /** Upload artifacts to GitHub Actions via [@actions/artifact]. */ + /** + * Artifact name, unique per action step in a workflow run. + * + * Artifact names must be unique within a run, and every job (or step) using + * the action uploads one, so include the attempt, job and step IDs. + */ + get name(): string { + const parts = [ + this.runId, + process.env.GITHUB_RUN_ATTEMPT, + process.env.GITHUB_JOB, + process.env.GITHUB_ACTION, + ].filter((part) => part !== undefined && part !== ""); + return ["capa_artifacts", ...parts].join("-"); + } + async upload(): Promise { const client = new DefaultArtifactClient(); await client.uploadArtifact( - "capa_artifacts-" + this.runId, + this.name, this.artifactFilenames .map((filename) => path.join(this.dir, filename)) .filter((filepath) => fs.existsSync(filepath)), diff --git a/test/instrumentation.test.ts b/test/instrumentation.test.ts index 123f169..8830f92 100644 --- a/test/instrumentation.test.ts +++ b/test/instrumentation.test.ts @@ -42,6 +42,18 @@ describe("instrumentation", () => { const artifacts = new Artifacts(dir, ARTIFACT_FILENAMES, debug); expect(artifacts.runId).toMatch(/^ghrunid-notfound-/); }); + + it("name in a workflow step includes attempt, job and step", () => { + vi.stubEnv("GITHUB_RUN_ATTEMPT", "2"); + vi.stubEnv("GITHUB_JOB", "list_versions"); + vi.stubEnv("GITHUB_ACTION", "execute"); + + const artifacts = new Artifacts("/dir", ARTIFACT_FILENAMES, false, "123"); + + expect(artifacts.name).toBe( + "capa_artifacts-123-2-list_versions-execute", + ); + }); }); describe("Instruments", () => {