Skip to content

Commit

Permalink
feat: rewrite format handling (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 6, 2024
1 parent d36b91c commit 789f114
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 39 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and r

## 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`.
* `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.
Expand Down Expand Up @@ -212,23 +213,24 @@ with:

If set the number is `<= 0`, the cache will be always invalidate (Not recommended).

### `annotations`
### `problem-matchers`

(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`)
and use the same default as golangci-lint (i.e. `colored-line-number`).
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`).

Works only with `colored-line-number` (the golangci-lint default).

https://golangci-lint.run/usage/configuration/#output-configuration

The default value is `true`.
The default value is `false`.

```yml
uses: golangci/golangci-lint-action@v5
with:
annotations: false
problem-matchers: true
# ...
```

Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ inputs:
restore existing caches, subject to other options.
default: 'false'
required: false
annotations:
description: "To Enable/disable GitHub Action annotations"
default: 'true'
problem-matchers:
description: "Force the usage of the embedded problem matchers"
default: 'false'
required: false
args:
description: "golangci-lint command line arguments"
Expand Down
29 changes: 19 additions & 10 deletions dist/post_run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions dist/run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions problem-matchers.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
31 changes: 21 additions & 10 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,32 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
const userArgsMap = new Map<string, string>(userArgsList)
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))

const annotations = core.getBooleanInput(`annotations`)
const problemMatchers = core.getBooleanInput(`problem-matchers`)

if (problemMatchers) {
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json")
if (fs.existsSync(matchersPath)) {
// Adds problem matchers.
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
core.info(`##[add-matcher]${matchersPath}`)
}
}

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(",")
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}`)
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
}

// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
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`)
Expand Down

0 comments on commit 789f114

Please sign in to comment.