diff --git a/README.md b/README.md index 1e781a37cb..4339a23360 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ jobs: # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. # skip-build-cache: true + + # Optional: if set to true then the action don't fail with just golangci-lint warnings. + # allow-warnings: true ``` We recommend running this action in a job separate from other jobs (`go test`, etc) diff --git a/action.yml b/action.yml index 35c8c77f11..8c510f1ddb 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,10 @@ inputs: description: "if set to true then the action don't cache or restore ~/.cache/go-build." default: false required: true + allow-warnings: + description: "if set to true then the action don't fail with just golangci-lint warnings." + default: false + required: false runs: using: "node12" main: "dist/run/index.js" diff --git a/dist/post_run/index.js b/dist/post_run/index.js index f97447b542..f266da7997 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -6860,7 +6860,14 @@ function runLint(lintPath, patchPath) { // TODO: support reviewdog or leaving comments by GitHub API. printOutput(exc); if (exc.code === 1) { - core.setFailed(`issues found`); + const allowWarnings = core.getInput(`allow-warnings`, { required: true }).trim(); + const errorRegex = /^::error.+$/m; + if (allowWarnings.toLowerCase() == "true" && !exc.stdout.match(errorRegex)) { + core.info(`golangci-lint found no errors`); + } + else { + core.setFailed(`issues found`); + } } else { core.setFailed(`golangci-lint exit with code ${exc.code}`); diff --git a/dist/run/index.js b/dist/run/index.js index d455344ea7..5bf2bc1dc5 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -6870,7 +6870,14 @@ function runLint(lintPath, patchPath) { // TODO: support reviewdog or leaving comments by GitHub API. printOutput(exc); if (exc.code === 1) { - core.setFailed(`issues found`); + const allowWarnings = core.getInput(`allow-warnings`, { required: true }).trim(); + const errorRegex = /^::error.+$/m; + if (allowWarnings.toLowerCase() == "true" && !exc.stdout.match(errorRegex)) { + core.info(`golangci-lint found no errors`); + } + else { + core.setFailed(`issues found`); + } } else { core.setFailed(`golangci-lint exit with code ${exc.code}`); diff --git a/src/run.ts b/src/run.ts index 66c7dbe9e6..f7285ddf1b 100644 --- a/src/run.ts +++ b/src/run.ts @@ -175,7 +175,13 @@ async function runLint(lintPath: string, patchPath: string): Promise { printOutput(exc) if (exc.code === 1) { - core.setFailed(`issues found`) + const allowWarnings = core.getInput(`allow-warnings`, { required: true }).trim() + const errorRegex = /^::error.+$/m + if (allowWarnings.toLowerCase() == "true" && !exc.stdout.match(errorRegex)) { + core.info(`golangci-lint found no errors`) + } else { + core.setFailed(`issues found`) + } } else { core.setFailed(`golangci-lint exit with code ${exc.code}`) }