Skip to content

Commit

Permalink
Fail CI on invalid config file
Browse files Browse the repository at this point in the history
  • Loading branch information
thehanimo committed Jan 27, 2023
1 parent fe23d65 commit 8464c95
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ Create a config file `.github/pr-title-checker-config.json` like this one below:
```
You can pass in one of `prefixes` or `regexp` or even both based on your use case. `regexpFlags` and `ignoreLables` are optional fields.

If `LABEL.name` is set to `""`, adding or removing labels will be skipped. The CI test will continue to pass/fail accordingly.

If none of the checks pass, a label will be added to that pull request. \
If at least one of them passes, the label will be removed.

This action causes CI tests to fail by default. However, if you don't want CI tests failing just because of this action, simply set `alwaysPassCI` as true in the CHECKS field.
This action causes CI tests to fail by default. However, if you do not want CI tests failing just because of this action, simply set `alwaysPassCI` as true in the CHECKS field. **An invalid config file will always cause the action to fail.**

Also, adding label names to the optional `ignoreLabels` field will forfeit any checks for PRs with those labels.

Expand All @@ -56,7 +58,7 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: thehanimo/[email protected].5
- uses: thehanimo/[email protected].6
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
Expand Down
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62894,11 +62894,12 @@ async function run() {
let config;
try {
config = await getJSON(configPath);
config = JSON.parse(config);
} catch (e) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(`Couldn't retrieve the config file specified - ${e}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(`Couldn't retrieve or parse the config file specified - ${e}`);
return;
}
let { CHECKS, LABEL, MESSAGES } = JSON.parse(config);
let { CHECKS, LABEL, MESSAGES } = config;
LABEL = LABEL || {};
LABEL.name = LABEL.name || "";
LABEL.color = LABEL.color || "eee";
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ async function run() {
let config;
try {
config = await getJSON(configPath);
config = JSON.parse(config);
} catch (e) {
core.setFailed(`Couldn't retrieve the config file specified - ${e}`);
core.setFailed(`Couldn't retrieve or parse the config file specified - ${e}`);
return;
}
let { CHECKS, LABEL, MESSAGES } = JSON.parse(config);
let { CHECKS, LABEL, MESSAGES } = config;
LABEL = LABEL || {};
LABEL.name = LABEL.name || "";
LABEL.color = LABEL.color || "eee";
Expand Down

0 comments on commit 8464c95

Please sign in to comment.