2019-09-09 21:20:59 +09:00
|
|
|
import { paths, parseConfig, isTag } from "./util";
|
2019-09-17 19:27:32 +09:00
|
|
|
import { release, upload, GitHubReleaser } from "./github";
|
2019-10-17 11:08:28 -04:00
|
|
|
import { setFailed, setOutput } from "@actions/core";
|
2019-09-09 21:20:59 +09:00
|
|
|
import { GitHub } from "@actions/github";
|
|
|
|
import { env } from "process";
|
2019-09-09 17:10:07 +09:00
|
|
|
|
|
|
|
async function run() {
|
|
|
|
try {
|
2019-09-09 20:16:58 +09:00
|
|
|
const config = parseConfig(env);
|
2019-09-09 17:10:07 +09:00
|
|
|
if (!isTag(config.github_ref)) {
|
|
|
|
throw new Error(`⚠️ GitHub Releases requires a tag`);
|
|
|
|
}
|
2019-10-02 20:51:12 -04:00
|
|
|
GitHub.plugin(require("@octokit/plugin-throttling"));
|
|
|
|
const gh = new GitHub(config.github_token, {
|
|
|
|
onRateLimit: (retryAfter, options) => {
|
|
|
|
console.warn(
|
|
|
|
`Request quota exhausted for request ${options.method} ${options.url}`
|
|
|
|
);
|
|
|
|
if (options.request.retryCount === 0) {
|
|
|
|
// only retries once
|
|
|
|
console.log(`Retrying after ${retryAfter} seconds!`);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onAbuseLimit: (retryAfter, options) => {
|
|
|
|
// does not retry, only logs a warning
|
|
|
|
console.warn(
|
|
|
|
`Abuse detected for request ${options.method} ${options.url}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-09-17 19:27:32 +09:00
|
|
|
let rel = await release(config, new GitHubReleaser(gh));
|
2019-09-09 17:10:07 +09:00
|
|
|
if (config.input_files) {
|
2019-09-09 21:20:59 +09:00
|
|
|
paths(config.input_files).forEach(async path => {
|
|
|
|
await upload(gh, rel.upload_url, path);
|
2019-09-09 17:10:07 +09:00
|
|
|
});
|
|
|
|
}
|
2019-09-09 21:20:59 +09:00
|
|
|
console.log(`🎉 Release ready at ${rel.html_url}`);
|
2019-10-17 11:08:28 -04:00
|
|
|
setOutput('url', rel.html_url);
|
2019-09-09 17:10:07 +09:00
|
|
|
} catch (error) {
|
2019-09-09 18:14:17 +09:00
|
|
|
setFailed(error.message);
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:20:59 +09:00
|
|
|
run();
|