/
main.ts
49 lines (47 loc) 路 1.58 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { paths, parseConfig, isTag } from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { setFailed, setOutput } from "@actions/core";
import { GitHub } from "@actions/github";
import { env } from "process";
async function run() {
try {
const config = parseConfig(env);
if (!config.input_tag_name && !isTag(config.github_ref)) {
throw new Error(`鈿狅笍 GitHub Releases requires a tag`);
}
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}`
);
}
});
let rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) {
const files = paths(config.input_files);
if (files.length == 0) {
console.warn(`馃 ${config.input_files} not include valid file.`);
}
files.forEach(async path => {
await upload(gh, rel.upload_url, path);
});
}
console.log(`馃帀 Release ready at ${rel.html_url}`);
setOutput("url", rel.html_url);
} catch (error) {
setFailed(error.message);
}
}
run();