From 60f4f0971ba636c8b4bbcfd3dc51ec969147099c Mon Sep 17 00:00:00 2001 From: Kazuto Iris <78157415+kazutoiris@users.noreply.github.com> Date: Sat, 28 Feb 2026 10:54:20 +0800 Subject: [PATCH] fix: implement overwrite for skip archive artifact When archive is set to false and overwrite is true, it now deletes existing artifact by filename before uploading new one. --- __tests__/upload.test.ts | 22 ++++++++++++++++++++++ dist/upload/index.js | 12 +++++++++++- src/upload/upload-artifact.ts | 11 ++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/__tests__/upload.test.ts b/__tests__/upload.test.ts index de81a1c..c6c4eca 100644 --- a/__tests__/upload.test.ts +++ b/__tests__/upload.test.ts @@ -327,4 +327,26 @@ describe('upload', () => { ) expect(artifact.default.uploadArtifact).not.toHaveBeenCalled() }) + + test('overwrite artifact by filename when archive is false', async () => { + mockInputs({ + [Inputs.Archive]: false, + [Inputs.Overwrite]: true + }) + + mockFindFilesToUpload.mockResolvedValue({ + filesToUpload: [fixtures.filesToUpload[0]], + rootDirectory: fixtures.rootDirectory + }) + + jest.spyOn(artifact.default, 'deleteArtifact').mockResolvedValue({ + id: 1337 + }) + + await run() + + expect(artifact.default.deleteArtifact).toHaveBeenCalledWith( + fixtures.filesToUpload[0].split('/').pop() || '' + ) + }) }) diff --git a/dist/upload/index.js b/dist/upload/index.js index a4ca651..26105cb 100644 --- a/dist/upload/index.js +++ b/dist/upload/index.js @@ -130585,7 +130585,17 @@ async function run() { return; } if (inputs.overwrite) { - await deleteArtifactIfExists(inputs.artifactName); + if (!inputs.archive) { + if (searchResult.filesToUpload.length > 0) { + const fileName = searchResult.filesToUpload[0].split('/').pop(); + if (fileName) { + deleteArtifactIfExists(fileName); + } + } + } + else { + await deleteArtifactIfExists(inputs.artifactName); + } } const options = {}; if (inputs.retentionDays) { diff --git a/src/upload/upload-artifact.ts b/src/upload/upload-artifact.ts index 432ec11..a038ce4 100644 --- a/src/upload/upload-artifact.ts +++ b/src/upload/upload-artifact.ts @@ -66,7 +66,16 @@ export async function run(): Promise { } if (inputs.overwrite) { - await deleteArtifactIfExists(inputs.artifactName) + if (!inputs.archive) { + if (searchResult.filesToUpload.length > 0) { + const fileName = searchResult.filesToUpload[0].split('/').pop() + if (fileName) { + deleteArtifactIfExists(fileName) + } + } + } else { + await deleteArtifactIfExists(inputs.artifactName) + } } const options: UploadArtifactOptions = {}