reintroduce octokit retry and throttling plugins

This commit is contained in:
softprops 2021-12-05 23:19:25 -05:00
parent 44946dc88f
commit 040bca2f2d
5 changed files with 494 additions and 87 deletions

View file

@ -3,13 +3,13 @@ import {
parseConfig,
isTag,
unmatchedPatterns,
uploadUrl
uploadUrl,
} from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { getOctokit } from "@actions/github";
import { Octokit } from "@octokit/action";
import { setFailed, setOutput } from "@actions/core";
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
import { env } from "process";
async function run() {
@ -24,7 +24,7 @@ async function run() {
}
if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files);
patterns.forEach(pattern =>
patterns.forEach((pattern) =>
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
);
if (patterns.length > 0 && config.input_fail_on_unmatched_files) {
@ -32,13 +32,9 @@ async function run() {
}
}
// const oktokit = GitHub.plugin(
// require("@octokit/plugin-throttling"),
// require("@octokit/plugin-retry")
// );
const gh = getOctokit(config.github_token, {
//new oktokit(
const OctokitWithPlugins = Octokit.plugin(retry, throttling);
const gh = new OctokitWithPlugins({
auth: config.github_token,
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(
@ -55,8 +51,8 @@ async function run() {
console.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
}
}
},
},
});
//);
const rel = await release(config, new GitHubReleaser(gh));
@ -67,7 +63,7 @@ async function run() {
}
const currentAssets = rel.assets;
const assets = await Promise.all(
files.map(async path => {
files.map(async (path) => {
const json = await upload(
config,
gh,
@ -78,7 +74,7 @@ async function run() {
delete json.uploader;
return json;
})
).catch(error => {
).catch((error) => {
throw error;
});
setOutput("assets", assets);