Skip to content

Commit

Permalink
Improve handling for failed check runs (#371)
Browse files Browse the repository at this point in the history
* Show full error message including documentation URL, see https://docs.github.com/en/rest/overview/resources-in-the-rest-api#client-errors
* Don't let the action fail if a check run could not be created
  • Loading branch information
ocean90 authored Jan 9, 2022
1 parent dc9e5a3 commit 917843d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/github/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,23 @@ async function createCheck(linterName, sha, context, lintResult, neutralCheckOnW
});
core.info(`${linterName} check created successfully`);
} catch (err) {
core.error(err);
throw new Error(`Error trying to create GitHub check for ${linterName}: ${err.message}`);
let errorMessage = err.message;
if (err.data) {
try {
const errorData = JSON.parse(err.data);
if (errorData.message) {
errorMessage += `. ${errorData.message}`;
}
if (errorData.documentation_url) {
errorMessage += ` ${errorData.documentation_url}`;
}
} catch (e) {
// Ignore
}
}
core.error(errorMessage);

throw new Error(`Error trying to create GitHub check for ${linterName}: ${errorMessage}`);
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,21 @@ async function runAction() {
}

core.startGroup("Create check runs with commit annotations");
await Promise.all(
checks.map(({ lintCheckName, lintResult, summary }) =>
createCheck(lintCheckName, headSha, context, lintResult, neutralCheckOnWarning, summary),
),
);
core.endGroup();
let groupClosed = false;
try {
await Promise.all(
checks.map(({ lintCheckName, lintResult, summary }) =>
createCheck(lintCheckName, headSha, context, lintResult, neutralCheckOnWarning, summary),
),
);
} catch (err) {
core.endGroup();
groupClosed = true;
core.warning("Some check runs could not be created.");
}
if (!groupClosed) {
core.endGroup();
}

if (hasFailures && !continueOnError) {
core.setFailed("Linting failures detected. See check runs with annotations for details.");
Expand Down

0 comments on commit 917843d

Please sign in to comment.