Fixes #12 Artifacts will now be replaced
This commit is contained in:
@@ -18,12 +18,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
class GithubArtifactUploader {
|
||||
constructor(releases) {
|
||||
constructor(releases, replacesExistingArtifacts) {
|
||||
this.replacesExistingArtifacts = true;
|
||||
this.releases = releases;
|
||||
this.replacesExistingArtifacts = replacesExistingArtifacts;
|
||||
}
|
||||
uploadArtifacts(artifacts, uploadUrl) {
|
||||
uploadArtifacts(artifacts, releaseId, uploadUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
artifacts.forEach((artifact) => __awaiter(this, void 0, void 0, function* () {
|
||||
if (this.replacesExistingArtifacts) {
|
||||
yield this.deleteUpdatedArtifacts(artifacts, releaseId);
|
||||
}
|
||||
for (const artifact of artifacts) {
|
||||
try {
|
||||
yield this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name);
|
||||
}
|
||||
@@ -31,7 +36,24 @@ class GithubArtifactUploader {
|
||||
const message = `Failed to upload artifact ${artifact.name}. Does it already exist?`;
|
||||
core.warning(message);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
deleteUpdatedArtifacts(artifacts, releaseId) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield this.releases.listArtifactsForRelease(releaseId);
|
||||
const releaseAssets = response.data;
|
||||
const assetByName = new Map();
|
||||
releaseAssets.forEach(asset => {
|
||||
assetByName[asset.name] = asset;
|
||||
});
|
||||
for (const artifact of artifacts) {
|
||||
const asset = assetByName[artifact.name];
|
||||
if (asset) {
|
||||
yield this.releases.deleteArtifact(asset.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user