From 6fa8b5b20443f11c2325fb6447d2d3adbd652daa Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 6 May 2024 18:21:48 +0200 Subject: [PATCH 1/4] feat: add an option to disable problem matchers --- README.md | 17 +++++++++++++++++ action.yml | 4 ++++ src/run.ts | 9 +++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e498a32a7..3702dfdae5 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,23 @@ with: # ... ``` +### `problem-matchers` + +(optional) + +To enable/disable GitHub Action annotations problem matchers (requires `annotations: true`). + +The problem matchers allows the display file information (path, position) inside the logs. + +The default value is `true`. + +```yml +uses: golangci/golangci-lint-action@v5 +with: + problem-matchers: false + # ... +``` + ### `args` (optional) diff --git a/action.yml b/action.yml index bb4a50870e..4a35def87d 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,10 @@ inputs: description: "To Enable/disable GitHub Action annotations" default: 'true' required: false + problem-matchers: + description: "To Enable/disable GitHub Action annotations problem matchers" + default: 'true' + required: false args: description: "golangci-lint command line arguments" default: "" diff --git a/src/run.ts b/src/run.ts index 9cffa9c690..e0d0114877 100644 --- a/src/run.ts +++ b/src/run.ts @@ -188,12 +188,17 @@ async function runLint(lintPath: string, patchPath: string): Promise { const annotations = core.getBooleanInput(`annotations`) if (annotations) { + let ghaFormat = `github-actions-problem-matchers` + if (!core.getBooleanInput(`problem-matchers`)) { + ghaFormat = `github-actions` + } + const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") + .filter((f) => !f.startsWith(ghaFormat)) + .concat(ghaFormat) .join(",") addedArgs.push(`--out-format=${formats}`) From bc23088233092241e06af4010bbfbcfc64d81c07 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 6 May 2024 18:24:33 +0200 Subject: [PATCH 2/4] chore: generate --- dist/post_run/index.js | 8 ++++++-- dist/run/index.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 87f67815a6..53d0a8470a 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89292,12 +89292,16 @@ async function runLint(lintPath, patchPath) { const userArgNames = new Set(userArgsList.map(([key]) => key)); const annotations = core.getBooleanInput(`annotations`); if (annotations) { + let ghaFormat = `github-actions-problem-matchers`; + if (!core.getBooleanInput(`problem-matchers`)) { + ghaFormat = `github-actions`; + } const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") + .filter((f) => !f.startsWith(ghaFormat)) + .concat(ghaFormat) .join(","); addedArgs.push(`--out-format=${formats}`); userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); diff --git a/dist/run/index.js b/dist/run/index.js index 11ef531598..7b892e73d8 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89292,12 +89292,16 @@ async function runLint(lintPath, patchPath) { const userArgNames = new Set(userArgsList.map(([key]) => key)); const annotations = core.getBooleanInput(`annotations`); if (annotations) { + let ghaFormat = `github-actions-problem-matchers`; + if (!core.getBooleanInput(`problem-matchers`)) { + ghaFormat = `github-actions`; + } const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") + .filter((f) => !f.startsWith(ghaFormat)) + .concat(ghaFormat) .join(","); addedArgs.push(`--out-format=${formats}`); userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); From 07a2113f55161127e5feb24e3306dba689778d03 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 6 May 2024 18:33:23 +0200 Subject: [PATCH 3/4] doc: update compatibility section --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3702dfdae5..be8bdee8ce 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,13 @@ The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and r ## Compatibility +* `v6.0.0+` works with `golangci-lint` version >= `v1.58.1`. * `v5.0.0+` removes `skip-pkg-cache` and `skip-build-cache` because the cache related to Go itself is already handled by `actions/setup-go`. * `v4.0.0+` requires an explicit `actions/setup-go` installation step before using this action: `uses: actions/setup-go@v5`. The `skip-go-installation` option has been removed. -* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3` -* `v1.2.2` is deprecated due to we forgot to change the minimum version of `golangci-lint` to `v1.28.3` ([issue](https://github.com/golangci/golangci-lint-action/issues/39)) -* `v1.2.1` works with `golangci-lint` version >= `v1.14.0` ([issue](https://github.com/golangci/golangci-lint-action/issues/39)) +* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3`. +* `v1.2.2` is deprecated due to we forgot to change the minimum version of `golangci-lint` to `v1.28.3` ([issue](https://github.com/golangci/golangci-lint-action/issues/39)). +* `v1.2.1` works with `golangci-lint` version >= `v1.14.0` ([issue](https://github.com/golangci/golangci-lint-action/issues/39)). ## How to use From 27164b28940091e2e662917dd9f14aa3d232a9a3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 6 May 2024 19:47:07 +0200 Subject: [PATCH 4/4] feat: embedded problem matchers --- README.md | 17 ----------------- action.yml | 4 ---- dist/post_run/index.js | 15 +++++++++++---- dist/run/index.js | 15 +++++++++++---- problem-matchers.json | 18 ++++++++++++++++++ src/run.ts | 18 ++++++++++++++---- 6 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 problem-matchers.json diff --git a/README.md b/README.md index be8bdee8ce..d7d97fd979 100644 --- a/README.md +++ b/README.md @@ -233,23 +233,6 @@ with: # ... ``` -### `problem-matchers` - -(optional) - -To enable/disable GitHub Action annotations problem matchers (requires `annotations: true`). - -The problem matchers allows the display file information (path, position) inside the logs. - -The default value is `true`. - -```yml -uses: golangci/golangci-lint-action@v5 -with: - problem-matchers: false - # ... -``` - ### `args` (optional) diff --git a/action.yml b/action.yml index 4a35def87d..bb4a50870e 100644 --- a/action.yml +++ b/action.yml @@ -40,10 +40,6 @@ inputs: description: "To Enable/disable GitHub Action annotations" default: 'true' required: false - problem-matchers: - description: "To Enable/disable GitHub Action annotations problem matchers" - default: 'true' - required: false args: description: "golangci-lint command line arguments" default: "" diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 53d0a8470a..c8d2b2f1d1 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89292,15 +89292,22 @@ async function runLint(lintPath, patchPath) { const userArgNames = new Set(userArgsList.map(([key]) => key)); const annotations = core.getBooleanInput(`annotations`); if (annotations) { - let ghaFormat = `github-actions-problem-matchers`; - if (!core.getBooleanInput(`problem-matchers`)) { - ghaFormat = `github-actions`; + // Skip the problem matchers installed by the binary, + // use the embedded files. + process.env.GOLANGCI_LINT_SKIP_GHA_PM_INSTALL = `true`; + const matchersPath = path.join(__dirname, "../..", "problem-matchers.json"); + let ghaFormat = `github-actions`; + if (fs.existsSync(matchersPath)) { + ghaFormat = `github-actions-problem-matchers`; + // Adds problem matchers. + // https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83 + core.info(`##[add-matcher]${matchersPath}`); } const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(ghaFormat)) + .filter((f) => !f.startsWith(`github-actions`)) .concat(ghaFormat) .join(","); addedArgs.push(`--out-format=${formats}`); diff --git a/dist/run/index.js b/dist/run/index.js index 7b892e73d8..4601494826 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89292,15 +89292,22 @@ async function runLint(lintPath, patchPath) { const userArgNames = new Set(userArgsList.map(([key]) => key)); const annotations = core.getBooleanInput(`annotations`); if (annotations) { - let ghaFormat = `github-actions-problem-matchers`; - if (!core.getBooleanInput(`problem-matchers`)) { - ghaFormat = `github-actions`; + // Skip the problem matchers installed by the binary, + // use the embedded files. + process.env.GOLANGCI_LINT_SKIP_GHA_PM_INSTALL = `true`; + const matchersPath = path.join(__dirname, "../..", "problem-matchers.json"); + let ghaFormat = `github-actions`; + if (fs.existsSync(matchersPath)) { + ghaFormat = `github-actions-problem-matchers`; + // Adds problem matchers. + // https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83 + core.info(`##[add-matcher]${matchersPath}`); } const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(ghaFormat)) + .filter((f) => !f.startsWith(`github-actions`)) .concat(ghaFormat) .join(","); addedArgs.push(`--out-format=${formats}`); diff --git a/problem-matchers.json b/problem-matchers.json new file mode 100644 index 0000000000..14f94bb601 --- /dev/null +++ b/problem-matchers.json @@ -0,0 +1,18 @@ +{ + "problemMatcher": [ + { + "owner": "golangci-lint-action", + "severity": "error", + "pattern": [ + { + "regexp": "^([^\\s]+)\\s+([^:]+):(\\d+):(?:(\\d+):)?\\s+(.+)$", + "file": 2, + "line": 3, + "column": 4, + "severity": 1, + "message": 5 + } + ] + } + ] +} \ No newline at end of file diff --git a/src/run.ts b/src/run.ts index e0d0114877..e64e1a71e5 100644 --- a/src/run.ts +++ b/src/run.ts @@ -188,16 +188,26 @@ async function runLint(lintPath: string, patchPath: string): Promise { const annotations = core.getBooleanInput(`annotations`) if (annotations) { - let ghaFormat = `github-actions-problem-matchers` - if (!core.getBooleanInput(`problem-matchers`)) { - ghaFormat = `github-actions` + // Skip the problem matchers installed by the binary, + // use the embedded files. + process.env.GOLANGCI_LINT_SKIP_GHA_PM_INSTALL = `true` + + const matchersPath = path.join(__dirname, "../..", "problem-matchers.json") + + let ghaFormat = `github-actions` + if (fs.existsSync(matchersPath)) { + ghaFormat = `github-actions-problem-matchers` + + // Adds problem matchers. + // https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83 + core.info(`##[add-matcher]${matchersPath}`) } const formats = (userArgsMap.get("out-format") || "") .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(ghaFormat)) + .filter((f) => !f.startsWith(`github-actions`)) .concat(ghaFormat) .join(",")