cancel action if rate limit reached

This commit is contained in:
Raicuparta 2022-11-04 19:57:53 +00:00
parent 841764ae88
commit 94ccc0f79f
2 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,8 @@ import { Octokit } from "@octokit/action";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
export let rateLimitReached = false;
function createOctokit() {
const OctokitWithPlugins = Octokit.plugin(retry, throttling);
return new OctokitWithPlugins({
@ -21,6 +23,11 @@ function createOctokit() {
console.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
console.warn(
"Rate limit reached and no more retries left, set rateLimitReached flag."
);
rateLimitReached = true;
},
onAbuseLimit: (retryAfter: number, options: any) => {
// does not retry, only logs a warning

View File

@ -10,6 +10,7 @@ import { getInstallCounts } from "./get-install-counts";
import { writeFile } from "fs";
import { getSettledResult } from "./promises";
import { rateLimitReached } from "./get-octokit";
enum Input {
outFile = "out-file",
@ -103,7 +104,13 @@ async function run() {
releases: modListWithAnalytics.filter(({ alpha }) => !alpha),
alphaReleases: modListWithAnalytics.filter(({ alpha }) => alpha),
});
core.setOutput(Output.releases, databaseJson);
if (rateLimitReached) {
core.setFailed("Rate limit reached");
return;
} else {
core.setOutput(Output.releases, databaseJson);
}
const outputFilePath = core.getInput(Input.outFile);