regenerate js, log on tag miss for debugging

This commit is contained in:
softprops 2019-09-17 17:12:53 +09:00
parent 5f2e9fb50f
commit f3c225f2b8
3 changed files with 52 additions and 5 deletions

View file

@ -8,10 +8,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const mime_1 = require("mime");
const path_1 = require("path");
class GitHubReleaseer {
constructor(github) {
this.github = github;
}
getReleaseByTag(params) {
return this.github.repos.getReleaseByTag(params);
}
createRelease(params) {
return this.github.repos.createRelease(params);
}
allReleases(params) {
return this.github.paginate.iterator(this.github.repos.listReleases.endpoint.merge(params));
}
}
exports.GitHubReleaseer = GitHubReleaseer;
exports.asset = (path) => {
return {
name: path_1.basename(path),
@ -36,11 +58,35 @@ exports.upload = (gh, url, path) => __awaiter(void 0, void 0, void 0, function*
file
});
});
exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* () {
exports.release = (config, releaser) => __awaiter(void 0, void 0, void 0, function* () {
var e_1, _a;
const [owner, repo] = config.github_repository.split("/");
const tag = config.github_ref.replace("refs/tags/", "");
try {
let release = yield gh.repos.getReleaseByTag({
// you can't get a an existing draft by tag
// so we must find one in the list of all releases
if (config.input_draft) {
try {
for (var _b = __asyncValues(releaser.allReleases({
owner,
repo
})), _c; _c = yield _b.next(), !_c.done;) {
const release = _c.value;
if (tag == release.data.tag_name) {
return release.data;
}
console.log(`release '${release.data.tag_name}' not equal to target tag '${tag}'`);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
let release = yield releaser.getReleaseByTag({
owner,
repo,
tag
@ -55,7 +101,7 @@ exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* ()
const body = config.input_body;
const draft = config.input_draft;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
let release = yield gh.repos.createRelease({
let release = yield releaser.createRelease({
owner,
repo,
tag_name,
@ -68,7 +114,7 @@ exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* ()
catch (error) {
// presume a race with competing metrix runs
console.log(`⚠️ GitHub release failed with status: ${error.status}, retrying...`);
return exports.release(config, gh);
return exports.release(config, releaser);
}
}
else {

View file

@ -22,7 +22,7 @@ function run() {
throw new Error(`⚠️ GitHub Releases requires a tag`);
}
const gh = new github_2.GitHub(config.github_token);
let rel = yield github_1.release(config, gh);
let rel = yield github_1.release(config, new github_1.GitHubReleaseer(gh));
if (config.input_files) {
util_1.paths(config.input_files).forEach((path) => __awaiter(this, void 0, void 0, function* () {
yield github_1.upload(gh, rel.upload_url, path);

View file

@ -122,6 +122,7 @@ export const release = async (
if (tag == release.data.tag_name) {
return release.data;
}
console.log(`release '${release.data.tag_name}' not equal to target tag '${tag}'`);
}
}
let release = await releaser.getReleaseByTag({