Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial fail-on-infos commit #16

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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