From fc7bbd5283bce15e0594f80a57e0d4ca070b4b4b Mon Sep 17 00:00:00 2001 From: Felix K <17876666+fkirc@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:25:10 +0100 Subject: [PATCH] Increase robustness in case of GitHub API failures (#302) * Increase robustness in case of GitHub API failures attempt to mitigate https://github.com/fkirc/skip-duplicate-actions/issues/301 --- dist/index.js | 13 ++++++++++++- src/main.ts | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index f8a26f3..6916e3b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -334,7 +334,18 @@ function main() { const repo = github.context.repo; const octokit = new Octokit((0, utils_1.getOctokitOptions)(token)); // Get and parse the current workflow run. - const { data: apiCurrentRun } = yield octokit.rest.actions.getWorkflowRun(Object.assign(Object.assign({}, repo), { run_id: github.context.runId })); + let apiCurrentRun = null; + try { + const res = yield octokit.rest.actions.getWorkflowRun(Object.assign(Object.assign({}, repo), { run_id: github.context.runId })); + apiCurrentRun = res.data; + } + catch (error) { + core.warning(error); + yield exitSuccess({ + shouldSkip: false, + reason: 'no_transferable_run' + }); + } const currentTreeHash = (_a = apiCurrentRun.head_commit) === null || _a === void 0 ? void 0 : _a.tree_id; if (!currentTreeHash) { exitFail(` diff --git a/src/main.ts b/src/main.ts index 835df57..b012c7e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -465,10 +465,20 @@ async function main(): Promise { const octokit = new Octokit(getOctokitOptions(token)) // Get and parse the current workflow run. - const {data: apiCurrentRun} = await octokit.rest.actions.getWorkflowRun({ - ...repo, - run_id: github.context.runId - }) + let apiCurrentRun: ApiWorkflowRun = null as unknown as ApiWorkflowRun + try { + const res = await octokit.rest.actions.getWorkflowRun({ + ...repo, + run_id: github.context.runId + }) + apiCurrentRun = res.data + } catch (error) { + core.warning(error as string | Error) + await exitSuccess({ + shouldSkip: false, + reason: 'no_transferable_run' + }) + } const currentTreeHash = apiCurrentRun.head_commit?.tree_id if (!currentTreeHash) { exitFail(`