From 7145ecb81a69104f99767cb133bf856e749f7e73 Mon Sep 17 00:00:00 2001 From: Daniel Chabr Date: Mon, 15 May 2023 22:34:56 +0200 Subject: [PATCH] Create allowFailure input to mask the dreaded red X (#14) * Add new allowFailure input * Add allowFailure documentation * Add if statement using allowFailure * Update check conclusion * Force variable to boolean * Do not set output * rebuild --------- Co-authored-by: Brian Pohl --- README.md | 1 + action.yml | 5 +++++ dist/index.cjs | 9 +++++++-- index.cjs | 9 +++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2cc121..f09ac9f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Github Action to check if a PR's labels pass the specified rules - `hasNone`: Comma separated list of labels, PR must not have any of them - `hasNotAll`: Comma separated list of labels, PR must not have all of them - `githubToken`: GitHub token +- `allowFailure`: When true, the action returns a successful exit code even if the label criteria are not met ## Output - `passed`: boolean diff --git a/action.yml b/action.yml index bcfef76..963b4c0 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,11 @@ inputs: githubToken: description: "The Github secret token to access PR check API" required: true + allowFailure: + description: 'When true, the action returns a successful exit code even if the label criteria are not met' + type: boolean + required: false + default: false outputs: passed: description: "Have the provided labels passed all tests?" diff --git a/dist/index.cjs b/dist/index.cjs index 601edb1..7d7fb33 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -10559,6 +10559,9 @@ async function run() { const hasNoneLabels = parseInputTags(hasNoneInput); const hasNotAllLabels = parseInputTags(hasNotAllInput); + const allowFailureInput = core.getInput("allowFailure"); + const allowFailure = allowFailureInput === "true"; + const failMessages = []; const { data: labelsOnIssue } = await octokit.issues.listLabelsOnIssue({ @@ -10629,7 +10632,7 @@ async function run() { await octokit.checks.update({ ...context.repo, check_run_id: id, - conclusion: "failure", + conclusion: allowFailure ? "success" : "failure", output: { title: "Labels did not pass provided rules", summary: failMessages.join(". "), @@ -10637,7 +10640,9 @@ async function run() { }); } - core.setFailed(failMessages.join(". ")); + if (!allowFailure) { + core.setFailed(failMessages.join(". ")); + } } else { // update old checks for (const id of checkRunIds) { diff --git a/index.cjs b/index.cjs index d76d4db..00ebfe6 100644 --- a/index.cjs +++ b/index.cjs @@ -23,6 +23,9 @@ async function run() { const hasNoneLabels = parseInputTags(hasNoneInput); const hasNotAllLabels = parseInputTags(hasNotAllInput); + const allowFailureInput = core.getInput("allowFailure"); + const allowFailure = allowFailureInput === "true"; + const failMessages = []; const { data: labelsOnIssue } = await octokit.issues.listLabelsOnIssue({ @@ -93,7 +96,7 @@ async function run() { await octokit.checks.update({ ...context.repo, check_run_id: id, - conclusion: "failure", + conclusion: allowFailure ? "success" : "failure", output: { title: "Labels did not pass provided rules", summary: failMessages.join(". "), @@ -101,7 +104,9 @@ async function run() { }); } - core.setFailed(failMessages.join(". ")); + if (!allowFailure) { + core.setFailed(failMessages.join(". ")); + } } else { // update old checks for (const id of checkRunIds) {