Update build artifacts
This commit is contained in:
@@ -12,11 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Action = void 0;
|
||||
const GithubError_1 = require("./GithubError");
|
||||
class Action {
|
||||
constructor(inputs, outputs, releases, uploader) {
|
||||
constructor(inputs, outputs, releases, uploader, artifactDestroyer) {
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.releases = releases;
|
||||
this.uploader = uploader;
|
||||
this.artifactDestroyer = artifactDestroyer;
|
||||
}
|
||||
perform() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -24,6 +25,9 @@ class Action {
|
||||
const releaseData = releaseResponse.data;
|
||||
const releaseId = releaseData.id;
|
||||
const uploadUrl = releaseData.upload_url;
|
||||
if (this.inputs.removeArtifacts) {
|
||||
yield this.artifactDestroyer.destroyArtifacts(releaseId);
|
||||
}
|
||||
const artifacts = this.inputs.artifacts;
|
||||
if (artifacts.length > 0) {
|
||||
yield this.uploader.uploadArtifacts(artifacts, releaseId, uploadUrl);
|
||||
|
||||
48
lib/ArtifactDestroyer.js
Normal file
48
lib/ArtifactDestroyer.js
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GithubArtifactDestroyer = void 0;
|
||||
const core = __importStar(require("@actions/core"));
|
||||
class GithubArtifactDestroyer {
|
||||
constructor(releases) {
|
||||
this.releases = releases;
|
||||
}
|
||||
destroyArtifacts(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.GithubArtifactDestroyer = GithubArtifactDestroyer;
|
||||
@@ -31,10 +31,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GithubArtifactUploader = void 0;
|
||||
const core = __importStar(require("@actions/core"));
|
||||
class GithubArtifactUploader {
|
||||
constructor(releases, replacesExistingArtifacts = true, removeArtifacts = false, throwsUploadErrors = false) {
|
||||
constructor(releases, replacesExistingArtifacts = true, throwsUploadErrors = false) {
|
||||
this.releases = releases;
|
||||
this.replacesExistingArtifacts = replacesExistingArtifacts;
|
||||
this.removeArtifacts = removeArtifacts;
|
||||
this.throwsUploadErrors = throwsUploadErrors;
|
||||
}
|
||||
uploadArtifacts(artifacts, releaseId, uploadUrl) {
|
||||
@@ -42,9 +41,6 @@ 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);
|
||||
}
|
||||
@@ -88,15 +84,5 @@ 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;
|
||||
|
||||
@@ -37,6 +37,7 @@ const ArtifactUploader_1 = require("./ArtifactUploader");
|
||||
const ArtifactGlobber_1 = require("./ArtifactGlobber");
|
||||
const GithubError_1 = require("./GithubError");
|
||||
const Outputs_1 = require("./Outputs");
|
||||
const ArtifactDestroyer_1 = require("./ArtifactDestroyer");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -57,7 +58,8 @@ function createAction() {
|
||||
const inputs = new Inputs_1.CoreInputs(globber, context);
|
||||
const outputs = new Outputs_1.CoreOutputs();
|
||||
const releases = new Releases_1.GithubReleases(inputs, git);
|
||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases, inputs.replacesArtifacts, inputs.removeArtifacts, inputs.artifactErrorsFailBuild);
|
||||
return new Action_1.Action(inputs, outputs, releases, uploader);
|
||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases, inputs.replacesArtifacts, inputs.artifactErrorsFailBuild);
|
||||
const artifactDestroyer = new ArtifactDestroyer_1.GithubArtifactDestroyer(releases);
|
||||
return new Action_1.Action(inputs, outputs, releases, uploader, artifactDestroyer);
|
||||
}
|
||||
run();
|
||||
|
||||
Reference in New Issue
Block a user