Skip to content

Commit

Permalink
Initial fail-on-infos commit (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgosalvez committed Nov 27, 2022
1 parent 2e7bfe4 commit fa037cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Create a workflow `.yml` file in your `.github/workflows` directory. An [example
### Inputs
For more information on these inputs, see the [Workflow syntax for GitHub Actions](https://docs.github.com/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith)

- `fail-on-infos`: The action fails if any info was found. This will always fail on errors. Optional. Default: `false`
- `fail-on-warnings`: The action fails if any warning was found. This will always fail on errors. Optional. Default: `false`
- `working-directory`: The working directory. Optional. Default: `./`
- `line-length`: The maximum line length. Optional. The formatter will use its default: `80`
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ async function run() {
try {
const workingDirectory = path.resolve(process.env.GITHUB_WORKSPACE, core.getInput('working-directory'))

const [analyzeErrorCount, analyzeWarningCount] = await analyze(workingDirectory);
const [analyzeErrorCount, analyzeWarningCount, analyzeInfoCount] = await analyze(workingDirectory);
const formatWarningCount = await format(workingDirectory);

const issueCount = analyzeErrorCount + analyzeWarningCount + formatWarningCount;
const issueCount = analyzeErrorCount + analyzeWarningCount + analyzeInfoCount + formatWarningCount;
const failOnInfos = core.getInput('fail-on-infos') === 'true';
const failOnWarnings = core.getInput('fail-on-warnings') === 'true';
const message = `${issueCount} issue${issueCount === 1 ? '' : 's'} found.`;

if (analyzeErrorCount > 0 || (failOnWarnings && issueCount > 0)) {
if (analyzeErrorCount > 0 || ((failOnInfos || failOnWarnings) && issueCount > 0)) {
core.setFailed(message);
} else {
console.log(message);
Expand Down Expand Up @@ -43,6 +44,7 @@ async function analyze(workingDirectory) {

let errorCount = 0;
let warningCount = 0;
let infoCount = 0;
const lines = output.trim().split(/\r?\n/);
const dataDelimiter = '|';

Expand All @@ -63,13 +65,16 @@ async function analyze(workingDirectory) {
if (lineData[0] === 'ERROR') {
console.log(`::error ${message}`);
errorCount++;
} else {
} else if (lineData[0] === 'WARNING') {
console.log(`::warning ${message}`);
warningCount++;
} else {
console.log(`::notice ${message}`);
infoCount++;
}
}

return [errorCount, warningCount];
return [errorCount, warningCount, infoCount];
}

async function format(workingDirectory) {
Expand Down

0 comments on commit fa037cd

Please sign in to comment.