From 168c94fc3c53bccc3a60f9fcf3154096c7e1ff58 Mon Sep 17 00:00:00 2001 From: Michael J Mulligan Date: Wed, 31 Mar 2021 16:40:36 +0100 Subject: [PATCH 1/2] Do not fail on only Warnings. --- action.yml | 4 ++++ dist/post_run/index.js | 9 ++++++++- dist/run/index.js | 9 ++++++++- src/run.ts | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) 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}`) } From a5ac6c357dfb07b279d18e94148807d7b31ea956 Mon Sep 17 00:00:00 2001 From: Michael J Mulligan Date: Wed, 31 Mar 2021 21:56:13 +0100 Subject: [PATCH 2/2] Add allow-warnings to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) 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)