mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-13 21:36:56 +00:00
fix: make diagnostic artifact names unique per step
Every job in a run uploaded capa_artifacts-<run id>, so only the first upload succeeded. Add the run attempt, job and step IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
efe85e637e
commit
72c96d31bc
|
|
@ -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<string> {
|
||||
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)),
|
||||
|
|
|
|||
|
|
@ -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", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue