feat: rewrite format handling (#1038)
This commit is contained in:
parent
d36b91c294
commit
789f114c52
14
README.md
14
README.md
@ -10,6 +10,7 @@ The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and r
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
|
* `v6.0.0+` removes `annotations` option.
|
||||||
* `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`.
|
* `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`.
|
* `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.
|
The `skip-go-installation` option has been removed.
|
||||||
@ -212,23 +213,24 @@ with:
|
|||||||
|
|
||||||
If set the number is `<= 0`, the cache will be always invalidate (Not recommended).
|
If set the number is `<= 0`, the cache will be always invalidate (Not recommended).
|
||||||
|
|
||||||
### `annotations`
|
### `problem-matchers`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
To enable/disable GitHub Action annotations.
|
Force the usage of the embedded problem matchers.
|
||||||
|
|
||||||
If disabled (`false`), the output format(s) will follow the golangci-lint configuration file (or CLI flags from `args`)
|
By default, the [problem matcher of Go (`actions/setup-go`)](https://github.com/actions/setup-go/blob/main/matchers.json) already handles the golangci-lint output (`colored-line-number`).
|
||||||
and use the same default as golangci-lint (i.e. `colored-line-number`).
|
|
||||||
|
Works only with `colored-line-number` (the golangci-lint default).
|
||||||
|
|
||||||
https://golangci-lint.run/usage/configuration/#output-configuration
|
https://golangci-lint.run/usage/configuration/#output-configuration
|
||||||
|
|
||||||
The default value is `true`.
|
The default value is `false`.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v5
|
uses: golangci/golangci-lint-action@v5
|
||||||
with:
|
with:
|
||||||
annotations: false
|
problem-matchers: true
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ inputs:
|
|||||||
restore existing caches, subject to other options.
|
restore existing caches, subject to other options.
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
annotations:
|
problem-matchers:
|
||||||
description: "To Enable/disable GitHub Action annotations"
|
description: "Force the usage of the embedded problem matchers"
|
||||||
default: 'true'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
args:
|
args:
|
||||||
description: "golangci-lint command line arguments"
|
description: "golangci-lint command line arguments"
|
||||||
|
31
dist/post_run/index.js
generated
vendored
31
dist/post_run/index.js
generated
vendored
@ -89290,18 +89290,27 @@ async function runLint(lintPath, patchPath) {
|
|||||||
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
||||||
const userArgsMap = new Map(userArgsList);
|
const userArgsMap = new Map(userArgsList);
|
||||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||||
const annotations = core.getBooleanInput(`annotations`);
|
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||||
if (annotations) {
|
if (problemMatchers) {
|
||||||
const formats = (userArgsMap.get("out-format") || "")
|
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json");
|
||||||
.trim()
|
if (fs.existsSync(matchersPath)) {
|
||||||
.split(",")
|
// Adds problem matchers.
|
||||||
.filter((f) => f.length > 0)
|
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||||
.filter((f) => !f.startsWith(`github-actions`))
|
core.info(`##[add-matcher]${matchersPath}`);
|
||||||
.concat("github-actions")
|
}
|
||||||
.join(",");
|
|
||||||
addedArgs.push(`--out-format=${formats}`);
|
|
||||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
|
||||||
}
|
}
|
||||||
|
const formats = (userArgsMap.get("out-format") || "")
|
||||||
|
.trim()
|
||||||
|
.split(",")
|
||||||
|
.filter((f) => f.length > 0)
|
||||||
|
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
|
||||||
|
.join(",");
|
||||||
|
if (formats) {
|
||||||
|
// Adds formats but without `github-actions` format.
|
||||||
|
addedArgs.push(`--out-format=${formats}`);
|
||||||
|
}
|
||||||
|
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||||
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||||
if (isOnlyNewIssues()) {
|
if (isOnlyNewIssues()) {
|
||||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
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`);
|
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||||
|
31
dist/run/index.js
generated
vendored
31
dist/run/index.js
generated
vendored
@ -89290,18 +89290,27 @@ async function runLint(lintPath, patchPath) {
|
|||||||
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
||||||
const userArgsMap = new Map(userArgsList);
|
const userArgsMap = new Map(userArgsList);
|
||||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||||
const annotations = core.getBooleanInput(`annotations`);
|
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||||
if (annotations) {
|
if (problemMatchers) {
|
||||||
const formats = (userArgsMap.get("out-format") || "")
|
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json");
|
||||||
.trim()
|
if (fs.existsSync(matchersPath)) {
|
||||||
.split(",")
|
// Adds problem matchers.
|
||||||
.filter((f) => f.length > 0)
|
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||||
.filter((f) => !f.startsWith(`github-actions`))
|
core.info(`##[add-matcher]${matchersPath}`);
|
||||||
.concat("github-actions")
|
}
|
||||||
.join(",");
|
|
||||||
addedArgs.push(`--out-format=${formats}`);
|
|
||||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
|
||||||
}
|
}
|
||||||
|
const formats = (userArgsMap.get("out-format") || "")
|
||||||
|
.trim()
|
||||||
|
.split(",")
|
||||||
|
.filter((f) => f.length > 0)
|
||||||
|
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
|
||||||
|
.join(",");
|
||||||
|
if (formats) {
|
||||||
|
// Adds formats but without `github-actions` format.
|
||||||
|
addedArgs.push(`--out-format=${formats}`);
|
||||||
|
}
|
||||||
|
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||||
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||||
if (isOnlyNewIssues()) {
|
if (isOnlyNewIssues()) {
|
||||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
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`);
|
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||||
|
17
problem-matchers.json
Normal file
17
problem-matchers.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "golangci-lint-colored-line-number",
|
||||||
|
"severity": "error",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^([^:]+):(\\d+):(?:(\\d+):)?\\s+(.+ \\(.+\\))$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"message": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
35
src/run.ts
35
src/run.ts
@ -185,21 +185,32 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
|||||||
const userArgsMap = new Map<string, string>(userArgsList)
|
const userArgsMap = new Map<string, string>(userArgsList)
|
||||||
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
||||||
|
|
||||||
const annotations = core.getBooleanInput(`annotations`)
|
const problemMatchers = core.getBooleanInput(`problem-matchers`)
|
||||||
|
|
||||||
if (annotations) {
|
if (problemMatchers) {
|
||||||
const formats = (userArgsMap.get("out-format") || "")
|
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json")
|
||||||
.trim()
|
if (fs.existsSync(matchersPath)) {
|
||||||
.split(",")
|
// Adds problem matchers.
|
||||||
.filter((f) => f.length > 0)
|
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||||
.filter((f) => !f.startsWith(`github-actions`))
|
core.info(`##[add-matcher]${matchersPath}`)
|
||||||
.concat("github-actions")
|
}
|
||||||
.join(",")
|
|
||||||
|
|
||||||
addedArgs.push(`--out-format=${formats}`)
|
|
||||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formats = (userArgsMap.get("out-format") || "")
|
||||||
|
.trim()
|
||||||
|
.split(",")
|
||||||
|
.filter((f) => f.length > 0)
|
||||||
|
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
|
||||||
|
.join(",")
|
||||||
|
|
||||||
|
if (formats) {
|
||||||
|
// Adds formats but without `github-actions` format.
|
||||||
|
addedArgs.push(`--out-format=${formats}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||||
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
||||||
|
|
||||||
if (isOnlyNewIssues()) {
|
if (isOnlyNewIssues()) {
|
||||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
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`)
|
throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user