Skip to content

Commit

Permalink
Create allowFailure input to mask the dreaded red X (#14)
Browse files Browse the repository at this point in the history
* 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 <bpohl@getplunk.com>
  • Loading branch information
danielchabr and Brian Pohl authored May 15, 2023
1 parent 76f3297 commit 7145ecb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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?"
Expand Down
9 changes: 7 additions & 2 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -10629,15 +10632,17 @@ 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(". "),
},
});
}

core.setFailed(failMessages.join(". "));
if (!allowFailure) {
core.setFailed(failMessages.join(". "));
}
} else {
// update old checks
for (const id of checkRunIds) {
Expand Down
9 changes: 7 additions & 2 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -93,15 +96,17 @@ 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(". "),
},
});
}

core.setFailed(failMessages.join(". "));
if (!allowFailure) {
core.setFailed(failMessages.join(". "));
}
} else {
// update old checks
for (const id of checkRunIds) {
Expand Down

0 comments on commit 7145ecb

Please sign in to comment.