@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
68 lines (67 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateCheckRun = updateCheckRun;
const tslib_1 = require("tslib");
const core = tslib_1.__importStar(require("@actions/core"));
const github = tslib_1.__importStar(require("@actions/github"));
const types_js_1 = require("../helpers/types.js");
const utils_js_1 = require("./utils.js");
const NOT_FOUND_RETRY_DELAYS_MS = [1000, 2000, 4000];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function updateWithNotFoundRetry(octokit, params) {
for (let attempt = 0;; attempt++) {
try {
return await octokit.rest.checks.update(params);
}
catch (error) {
const delay = NOT_FOUND_RETRY_DELAYS_MS[attempt];
if (error?.status !== 404 || delay === undefined) {
throw error;
}
core.warning(`Check run ${params.check_run_id} not found, retrying in ${delay}ms (attempt ${attempt + 1} of ${NOT_FOUND_RETRY_DELAYS_MS.length})`);
await sleep(delay);
}
}
}
async function updateCheckRun(octokit, checkId, { conclusion, output }) {
core.info(`Updating check: ${checkId}`);
const { title, summary, annotations = [] } = output;
const batches = (0, utils_js_1.batch)(annotations, 50);
core.info(`annotations to be sent: ${annotations.length}`);
await updateWithNotFoundRetry(octokit, {
check_run_id: checkId,
completed_at: new Date().toISOString(),
status: 'completed',
...github.context.repo,
conclusion,
output: {
title,
summary,
},
});
try {
for (const chunk of batches) {
await updateWithNotFoundRetry(octokit, {
check_run_id: checkId,
...github.context.repo,
output: {
title,
summary,
annotations: chunk,
},
});
core.info(`annotations sent (${chunk.length})`);
}
}
catch (error) {
core.error(`failed to send annotations: ${error}`);
throw error;
}
// Fail
if (conclusion === types_js_1.CheckConclusion.Failure) {
return core.setFailed(output.title);
}
// Success or Neutral
}