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

@@ -31,9 +31,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.GithubArtifactUploader = void 0;
const core = __importStar(require("@actions/core"));
class GithubArtifactUploader {
constructor(releases, replacesExistingArtifacts = true, throwsUploadErrors = false) {
constructor(releases, replacesExistingArtifacts = true, removeArtifacts = false, throwsUploadErrors = false) {
this.releases = releases;
this.replacesExistingArtifacts = replacesExistingArtifacts;
this.removeArtifacts = removeArtifacts;
this.throwsUploadErrors = throwsUploadErrors;
}
uploadArtifacts(artifacts, releaseId, uploadUrl) {
@@ -41,6 +42,9 @@ class GithubArtifactUploader {
if (this.replacesExistingArtifacts) {
yield this.deleteUpdatedArtifacts(artifacts, releaseId);
}
if (this.removeArtifacts) {
yield this.deleteUploadedArtifacts(releaseId);
}
for (const artifact of artifacts) {
yield this.uploadArtifact(artifact, releaseId, uploadUrl);
}
@@ -84,5 +88,15 @@ class GithubArtifactUploader {
}
});
}
deleteUploadedArtifacts(releaseId) {
return __awaiter(this, void 0, void 0, function* () {
const releaseAssets = yield this.releases.listArtifactsForRelease(releaseId);
for (const artifact of releaseAssets) {
const asset = artifact;
core.debug(`Deleting existing artifact ${artifact.name}...`);
yield this.releases.deleteArtifact(asset.id);
}
});
}
}
exports.GithubArtifactUploader = GithubArtifactUploader;