From aebff4bd9cd0198ff4f020915c27258a9edc4c01 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 01:36:48 +0200 Subject: [PATCH] feat: add option to enable/disable annotations --- README.md | 12 ++++++++++++ action.yml | 4 ++++ dist/post_run/index.js | 21 ++++++++++++--------- dist/run/index.js | 21 ++++++++++++--------- src/run.ts | 24 ++++++++++++++---------- 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4f8d941830..b33532660f 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,18 @@ with: # ... ``` +`annotations`: (optional) To enable/disable GitHub Action annotations. +If disabled (`false`), the output format(s) will follow the golangci-lint configuration file and use the same default as golangci-lint (i.e. `colored-line-number`). +https://golangci-lint.run/usage/configuration/#output-configuration +The default value is `true`. + +```yml +uses: golangci/golangci-lint-action@v5 +with: + annotations: false + # ... +``` + `args`: (optional) golangci-lint command line arguments. Note: By default, the `.golangci.yml` file should be at the root of the repository. The location of the configuration file can be changed by using `--config=` diff --git a/action.yml b/action.yml index a85cf66f1e..b498ad078f 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,10 @@ inputs: restore existing caches, subject to other options. default: 'false' required: false + annotations: + description: "To Enable/disable GitHub Action annotations" + 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 9dd2226db6..b6746c4c53 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89287,15 +89287,18 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(","); - addedArgs.push(`--out-format=${formats}`); - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + const annotations = core.getInput(`annotations`).trim() !== "false"; + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(","); + addedArgs.push(`--out-format=${formats}`); + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + } if (isOnlyNewIssues()) { if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { throw new Error(`please, don't specify manually --new* args when requesting only new issues`); diff --git a/dist/run/index.js b/dist/run/index.js index b015ef3b3f..278dc9a2c6 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89287,15 +89287,18 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(","); - addedArgs.push(`--out-format=${formats}`); - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + const annotations = core.getInput(`annotations`).trim() !== "false"; + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(","); + addedArgs.push(`--out-format=${formats}`); + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + } if (isOnlyNewIssues()) { if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { throw new Error(`please, don't specify manually --new* args when requesting only new issues`); diff --git a/src/run.ts b/src/run.ts index 60ff43201b..db8cf53a50 100644 --- a/src/run.ts +++ b/src/run.ts @@ -192,16 +192,20 @@ async function runLint(lintPath: string, patchPath: string): Promise { const userArgsMap = new Map(userArgsList) const userArgNames = new Set(userArgsList.map(([key]) => key)) - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(",") - - addedArgs.push(`--out-format=${formats}`) - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim() + const annotations = core.getInput(`annotations`).trim() !== "false" + + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(",") + + addedArgs.push(`--out-format=${formats}`) + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim() + } if (isOnlyNewIssues()) { if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {