Fixes #12 Artifacts will now be replaced
This commit is contained in:
@@ -18,10 +18,12 @@ class Action {
|
||||
}
|
||||
perform() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const uploadUrl = yield this.createOrUpdateRelease();
|
||||
const releaseResponse = yield this.createOrUpdateRelease();
|
||||
const releaseId = releaseResponse.id;
|
||||
const uploadUrl = releaseResponse.upload_url;
|
||||
const artifacts = this.inputs.artifacts;
|
||||
if (artifacts.length > 0) {
|
||||
yield this.uploader.uploadArtifacts(artifacts, uploadUrl);
|
||||
yield this.uploader.uploadArtifacts(artifacts, releaseId, uploadUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -49,7 +51,7 @@ class Action {
|
||||
updateRelease(id) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name, this.inputs.prerelease);
|
||||
return response.data.upload_url;
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
noPublishedRelease(error) {
|
||||
@@ -80,7 +82,7 @@ class Action {
|
||||
createRelease() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name, this.inputs.prerelease);
|
||||
return response.data.upload_url;
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,12 @@ class CoreInputs {
|
||||
return this.tag;
|
||||
}
|
||||
get prerelease() {
|
||||
const draft = core.getInput('prerelease');
|
||||
return draft == 'true';
|
||||
const preRelease = core.getInput('prerelease');
|
||||
return preRelease == 'true';
|
||||
}
|
||||
get replacesArtifacts() {
|
||||
const replaces = core.getInput('replacesArtifacts');
|
||||
return replaces == 'true';
|
||||
}
|
||||
get tag() {
|
||||
const tag = core.getInput('tag');
|
||||
|
||||
@@ -43,7 +43,7 @@ function createAction() {
|
||||
const globber = new ArtifactGlobber_1.FileArtifactGlobber();
|
||||
const inputs = new Inputs_1.CoreInputs(globber, context);
|
||||
const releases = new Releases_1.GithubReleases(context, git);
|
||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases);
|
||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases, inputs.replacesArtifacts);
|
||||
return new Action_1.Action(inputs, releases, uploader);
|
||||
}
|
||||
run();
|
||||
|
||||
@@ -28,6 +28,24 @@ class GithubReleases {
|
||||
});
|
||||
});
|
||||
}
|
||||
deleteArtifact(assetId) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.git.repos.deleteReleaseAsset({
|
||||
asset_id: assetId,
|
||||
owner: this.context.repo.owner,
|
||||
repo: this.context.repo.repo
|
||||
});
|
||||
});
|
||||
}
|
||||
listArtifactsForRelease(releaseId) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.git.repos.listAssetsForRelease({
|
||||
owner: this.context.repo.owner,
|
||||
release_id: releaseId,
|
||||
repo: this.context.repo.repo
|
||||
});
|
||||
});
|
||||
}
|
||||
listReleases() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.git.repos.listReleases({
|
||||
|
||||
Reference in New Issue
Block a user