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.
This commit is contained in:
Kazuto Iris 2026-02-28 10:54:20 +08:00
parent bbbca2ddaa
commit 60f4f0971b
No known key found for this signature in database
3 changed files with 43 additions and 2 deletions

View file

@ -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() || ''
)
})
})

12
dist/upload/index.js vendored
View file

@ -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) {

View file

@ -66,7 +66,16 @@ export async function run(): Promise<void> {
}
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 = {}