Fixes #1 Allow for multiple artifacts
This commit is contained in:
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class Action {
|
||||
constructor(inputs, releases) {
|
||||
constructor(inputs, releases, uploader) {
|
||||
this.inputs = inputs;
|
||||
this.releases = releases;
|
||||
this.uploader = uploader;
|
||||
}
|
||||
perform() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const createResult = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
|
||||
if (this.inputs.artifact) {
|
||||
const artifactData = this.inputs.readArtifact();
|
||||
yield this.releases.uploadArtifact(createResult.data.upload_url, this.inputs.artifactContentLength, this.inputs.artifactContentType, artifactData, this.inputs.artifactName);
|
||||
const artifacts = this.inputs.artifacts;
|
||||
if (artifacts.length > 0) {
|
||||
yield this.uploader.uploadArtifacts(artifacts, createResult.data.upload_url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
18
lib/Artifact.js
Normal file
18
lib/Artifact.js
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = require("path");
|
||||
const fs_1 = require("fs");
|
||||
class Artifact {
|
||||
constructor(path, contentType = "raw") {
|
||||
this.path = path;
|
||||
this.name = path_1.basename(path);
|
||||
this.contentType = contentType;
|
||||
}
|
||||
get contentLength() {
|
||||
return fs_1.statSync(this.path).size;
|
||||
}
|
||||
readFile() {
|
||||
return fs_1.readFileSync(this.path);
|
||||
}
|
||||
}
|
||||
exports.Artifact = Artifact;
|
||||
16
lib/ArtifactGlobber.js
Normal file
16
lib/ArtifactGlobber.js
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Globber_1 = require("./Globber");
|
||||
const Artifact_1 = require("./Artifact");
|
||||
class FileArtifactGlobber {
|
||||
constructor(globber = new Globber_1.FileGlobber()) {
|
||||
this.globber = globber;
|
||||
}
|
||||
globArtifactString(artifact, contentType) {
|
||||
return artifact.split(',')
|
||||
.map((path) => this.globber.glob(path))
|
||||
.reduce((accumulated, current) => accumulated.concat(current))
|
||||
.map((path) => new Artifact_1.Artifact(path, contentType));
|
||||
}
|
||||
}
|
||||
exports.FileArtifactGlobber = FileArtifactGlobber;
|
||||
23
lib/ArtifactUploader.js
Normal file
23
lib/ArtifactUploader.js
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class GithubArtifactUploader {
|
||||
constructor(releases) {
|
||||
this.releases = releases;
|
||||
}
|
||||
uploadArtifacts(artifacts, uploadUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
artifacts.forEach((artifact) => __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name);
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.GithubArtifactUploader = GithubArtifactUploader;
|
||||
9
lib/Globber.js
Normal file
9
lib/Globber.js
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const glob_1 = require("glob");
|
||||
class FileGlobber {
|
||||
glob(pattern) {
|
||||
return new glob_1.GlobSync(pattern, { mark: true }).found;
|
||||
}
|
||||
}
|
||||
exports.FileGlobber = FileGlobber;
|
||||
@@ -9,26 +9,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
class CoreInputs {
|
||||
constructor(context) {
|
||||
constructor(artifactGlobber, context) {
|
||||
this.artifactGlobber = artifactGlobber;
|
||||
this.context = context;
|
||||
}
|
||||
get artifact() {
|
||||
return core.getInput('artifact');
|
||||
}
|
||||
get artifactName() {
|
||||
return path_1.basename(this.artifact);
|
||||
}
|
||||
get artifactContentType() {
|
||||
const type = core.getInput('artifactContentType');
|
||||
if (type) {
|
||||
return type;
|
||||
get artifacts() {
|
||||
let artifacts = core.getInput('artifacts');
|
||||
if (!artifacts) {
|
||||
artifacts = core.getInput('artifacts');
|
||||
}
|
||||
return 'raw';
|
||||
}
|
||||
get artifactContentLength() {
|
||||
return fs_1.statSync(this.artifact).size;
|
||||
if (artifacts) {
|
||||
let contentType = core.getInput('artifactContentType');
|
||||
if (!contentType) {
|
||||
contentType = 'raw';
|
||||
}
|
||||
return this.artifactGlobber
|
||||
.globArtifactString(artifacts, contentType);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
get body() {
|
||||
const body = core.getInput('body');
|
||||
@@ -70,9 +69,6 @@ class CoreInputs {
|
||||
get token() {
|
||||
return core.getInput('token', { required: true });
|
||||
}
|
||||
readArtifact() {
|
||||
return fs_1.readFileSync(this.artifact);
|
||||
}
|
||||
stringFromFile(path) {
|
||||
return fs_1.readFileSync(path, 'utf-8');
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ const core = __importStar(require("@actions/core"));
|
||||
const Inputs_1 = require("./Inputs");
|
||||
const Releases_1 = require("./Releases");
|
||||
const Action_1 = require("./Action");
|
||||
const ArtifactUploader_1 = require("./ArtifactUploader");
|
||||
const ArtifactGlobber_1 = require("./ArtifactGlobber");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -35,8 +37,10 @@ function createAction() {
|
||||
const token = core.getInput('token');
|
||||
const context = github.context;
|
||||
const git = new github.GitHub(token);
|
||||
const globber = new ArtifactGlobber_1.FileArtifactGlobber();
|
||||
const inputs = new Inputs_1.CoreInputs(globber, context);
|
||||
const releases = new Releases_1.GithubReleases(context, git);
|
||||
const inputs = new Inputs_1.CoreInputs(context);
|
||||
return new Action_1.Action(inputs, releases);
|
||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases);
|
||||
return new Action_1.Action(inputs, releases, uploader);
|
||||
}
|
||||
run();
|
||||
|
||||
Reference in New Issue
Block a user