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 = {}