Skip to content

Commit

Permalink
Only fail check if fail_below_threshold is set (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannseman authored Nov 3, 2021
1 parent 9f77942 commit 216f8b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A check is added to the workflow run.

![alt text](img/check.png "Check with metrics")

The check will suceed or fail based on your threshold, this allows you to mandate coverage checks pass on your [protected branches](https://docs.github.com/en/github/administering-a-repository/defining-the-mergeability-of-pull-requests/about-protected-branches).
The check will succeed or fail based on your threshold when `fail_below_threshold` is set to `true`, this allows you to mandate coverage checks pass on your [protected branches](https://docs.github.com/en/github/administering-a-repository/defining-the-mergeability-of-pull-requests/about-protected-branches).

## Inputs

Expand Down
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18223,7 +18223,12 @@ async function action(payload) {
if (pullRequestNumber) {
await addComment(pullRequestNumber, comment, reportName);
}
await addCheck(comment, reportName, commit, belowThreshold);
await addCheck(
comment,
reportName,
commit,
failBelowThreshold ? (belowThreshold ? "failure" : "success") : "neutral"
);

if (failBelowThreshold && belowThreshold) {
core.setFailed("Minimum coverage requirement was not satisfied");
Expand Down Expand Up @@ -18348,14 +18353,14 @@ async function addComment(pullRequestNumber, body, reportName) {
}
}

async function addCheck(body, reportName, sha, belowThreshold) {
async function addCheck(body, reportName, sha, conclusion) {
const checkName = reportName ? reportName : "coverage";

await client.rest.checks.create({
name: checkName,
head_sha: sha,
status: "completed",
conclusion: belowThreshold ? "failure" : "success",
conclusion: conclusion,
output: {
title: checkName,
summary: body,
Expand Down
11 changes: 8 additions & 3 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ async function action(payload) {
if (pullRequestNumber) {
await addComment(pullRequestNumber, comment, reportName);
}
await addCheck(comment, reportName, commit, belowThreshold);
await addCheck(
comment,
reportName,
commit,
failBelowThreshold ? (belowThreshold ? "failure" : "success") : "neutral"
);

if (failBelowThreshold && belowThreshold) {
core.setFailed("Minimum coverage requirement was not satisfied");
Expand Down Expand Up @@ -194,14 +199,14 @@ async function addComment(pullRequestNumber, body, reportName) {
}
}

async function addCheck(body, reportName, sha, belowThreshold) {
async function addCheck(body, reportName, sha, conclusion) {
const checkName = reportName ? reportName : "coverage";

await client.rest.checks.create({
name: checkName,
head_sha: sha,
status: "completed",
conclusion: belowThreshold ? "failure" : "success",
conclusion: conclusion,
output: {
title: checkName,
summary: body,
Expand Down
3 changes: 2 additions & 1 deletion src/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ test("action triggered by push", async () => {
process.env["INPUT_SHOW_BRANCH"] = "false";
process.env["INPUT_SHOW_LINE"] = "false";
process.env["INPUT_MINIMUM_COVERAGE"] = "100";
process.env["INPUT_FAIL_BELOW_THRESHOLD"] = "true";
process.env["INPUT_SHOW_CLASS_NAMES"] = "false";
process.env["INPUT_ONLY_CHANGED_FILES"] = "false";

Expand Down Expand Up @@ -655,7 +656,7 @@ test("addCheck", async () => {
.post(`/repos/${owner}/${repo}/check-runs`)
.reply(200);

await addCheck("foo", "bar", "fake_sha");
await addCheck("foo", "bar", "fake_sha", "success");

expect(checkRunMock.pendingMocks().length).toBe(0);
});

0 comments on commit 216f8b9

Please sign in to comment.