feat: embedded problem matchers

This commit is contained in:
Fernandez Ludovic 2024-05-06 19:47:07 +02:00
parent 07a2113f55
commit 27164b2894
6 changed files with 54 additions and 33 deletions

View file

@ -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` ### `args`
(optional) (optional)

View file

@ -40,10 +40,6 @@ inputs:
description: "To Enable/disable GitHub Action annotations" description: "To Enable/disable GitHub Action annotations"
default: 'true' default: 'true'
required: false required: false
problem-matchers:
description: "To Enable/disable GitHub Action annotations problem matchers"
default: 'true'
required: false
args: args:
description: "golangci-lint command line arguments" description: "golangci-lint command line arguments"
default: "" default: ""

15
dist/post_run/index.js generated vendored
View file

@ -89292,15 +89292,22 @@ async function runLint(lintPath, patchPath) {
const userArgNames = new Set(userArgsList.map(([key]) => key)); const userArgNames = new Set(userArgsList.map(([key]) => key));
const annotations = core.getBooleanInput(`annotations`); const annotations = core.getBooleanInput(`annotations`);
if (annotations) { if (annotations) {
let ghaFormat = `github-actions-problem-matchers`; // Skip the problem matchers installed by the binary,
if (!core.getBooleanInput(`problem-matchers`)) { // use the embedded files.
ghaFormat = `github-actions`; 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") || "") const formats = (userArgsMap.get("out-format") || "")
.trim() .trim()
.split(",") .split(",")
.filter((f) => f.length > 0) .filter((f) => f.length > 0)
.filter((f) => !f.startsWith(ghaFormat)) .filter((f) => !f.startsWith(`github-actions`))
.concat(ghaFormat) .concat(ghaFormat)
.join(","); .join(",");
addedArgs.push(`--out-format=${formats}`); addedArgs.push(`--out-format=${formats}`);

15
dist/run/index.js generated vendored
View file

@ -89292,15 +89292,22 @@ async function runLint(lintPath, patchPath) {
const userArgNames = new Set(userArgsList.map(([key]) => key)); const userArgNames = new Set(userArgsList.map(([key]) => key));
const annotations = core.getBooleanInput(`annotations`); const annotations = core.getBooleanInput(`annotations`);
if (annotations) { if (annotations) {
let ghaFormat = `github-actions-problem-matchers`; // Skip the problem matchers installed by the binary,
if (!core.getBooleanInput(`problem-matchers`)) { // use the embedded files.
ghaFormat = `github-actions`; 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") || "") const formats = (userArgsMap.get("out-format") || "")
.trim() .trim()
.split(",") .split(",")
.filter((f) => f.length > 0) .filter((f) => f.length > 0)
.filter((f) => !f.startsWith(ghaFormat)) .filter((f) => !f.startsWith(`github-actions`))
.concat(ghaFormat) .concat(ghaFormat)
.join(","); .join(",");
addedArgs.push(`--out-format=${formats}`); addedArgs.push(`--out-format=${formats}`);

18
problem-matchers.json Normal file
View file

@ -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
}
]
}
]
}

View file

@ -188,16 +188,26 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
const annotations = core.getBooleanInput(`annotations`) const annotations = core.getBooleanInput(`annotations`)
if (annotations) { if (annotations) {
let ghaFormat = `github-actions-problem-matchers` // Skip the problem matchers installed by the binary,
if (!core.getBooleanInput(`problem-matchers`)) { // use the embedded files.
ghaFormat = `github-actions` 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") || "") const formats = (userArgsMap.get("out-format") || "")
.trim() .trim()
.split(",") .split(",")
.filter((f) => f.length > 0) .filter((f) => f.length > 0)
.filter((f) => !f.startsWith(ghaFormat)) .filter((f) => !f.startsWith(`github-actions`))
.concat(ghaFormat) .concat(ghaFormat)
.join(",") .join(",")