Add removeArtifacts (#109)

This commit is contained in:
Rosalie
2021-09-07 00:57:37 +02:00
committed by GitHub
parent a4f828a4e5
commit f597c8ad62
12 changed files with 81 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ export class GithubArtifactUploader implements ArtifactUploader {
constructor(
private releases: Releases,
private replacesExistingArtifacts: boolean = true,
private removeArtifacts: boolean = false,
private throwsUploadErrors: boolean = false,
) {
}
@@ -20,6 +21,9 @@ export class GithubArtifactUploader implements ArtifactUploader {
if (this.replacesExistingArtifacts) {
await this.deleteUpdatedArtifacts(artifacts, releaseId)
}
if (this.removeArtifacts) {
await this.deleteUploadedArtifacts(releaseId)
}
for (const artifact of artifacts) {
await this.uploadArtifact(artifact, releaseId, uploadUrl)
}
@@ -65,4 +69,13 @@ export class GithubArtifactUploader implements ArtifactUploader {
}
}
}
private async deleteUploadedArtifacts(releaseId: number): Promise<void> {
const releaseAssets = await this.releases.listArtifactsForRelease(releaseId)
for (const artifact of releaseAssets) {
const asset = artifact
core.debug(`Deleting existing artifact ${artifact.name}...`)
await this.releases.deleteArtifact(asset.id)
}
}
}