From 216f8b9e94d15b6face56d1b7aa97413224e3047 Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Wed, 3 Nov 2021 17:55:57 +0100 Subject: [PATCH] Only fail check if fail_below_threshold is set (#55) --- README.md | 2 +- dist/index.js | 11 ++++++++--- src/action.js | 11 ++++++++--- src/action.test.js | 3 ++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ed28685e..e01a37d7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 31e63aeb..acaf75f5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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"); @@ -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, diff --git a/src/action.js b/src/action.js index fa793255..26e88e56 100644 --- a/src/action.js +++ b/src/action.js @@ -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"); @@ -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, diff --git a/src/action.test.js b/src/action.test.js index e96dde9f..18fd72d2 100644 --- a/src/action.test.js +++ b/src/action.test.js @@ -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"; @@ -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); });