Skip to content

Commit 01ad366

Browse files
committed
feat: golangci-lint v2 support
1 parent eb5c0cc commit 01ad366

File tree

13 files changed

+68
-87
lines changed

13 files changed

+68
-87
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
version:
5555
- ""
5656
- "latest"
57-
- "v1.63" # TODO(ldez): it should be updated for v2.
58-
- "v1.63.4" # TODO(ldez): it should be updated for v2.
57+
- "v2.0"
58+
- "v2.0.0"
5959
runs-on: ${{ matrix.os }}
6060
permissions:
6161
contents: read
@@ -83,8 +83,8 @@ jobs:
8383
version:
8484
- ""
8585
- "latest"
86-
- "v1.63.4" # TODO(ldez): it should be updated for v2.
87-
- "95c39ac1fbaf66475705c06c16259ffd9d6bf9a2" # TODO(ldez): it should be updated for v2.
86+
- "v2.0.0"
87+
- "95c39ac1fbaf66475705c06c16259ffd9d6bf9a2" # FIXME(ldez): it should be updated for v2.
8888
runs-on: ${{ matrix.os }}
8989
permissions:
9090
contents: read

.golangci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
version: "2"
2+
13
output:
24
show-stats: true
3-
sort-results: true
45
sort-order:
6+
- file
57
- linter
6-
- file

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454
with:
5555
go-version: stable
5656
- name: golangci-lint
57-
uses: golangci/golangci-lint-action@v6
57+
uses: golangci/golangci-lint-action@v7
5858
with:
59-
version: v1.64
59+
version: v2.0
6060
```
6161
6262
</details>
@@ -92,9 +92,9 @@ jobs:
9292
with:
9393
go-version: ${{ matrix.go }}
9494
- name: golangci-lint
95-
uses: golangci/golangci-lint-action@v6
95+
uses: golangci/golangci-lint-action@v7
9696
with:
97-
version: v1.64
97+
version: v2.0
9898
```
9999
100100
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
@@ -120,7 +120,7 @@ on:
120120
121121
env:
122122
GO_VERSION: stable
123-
GOLANGCI_LINT_VERSION: v1.64
123+
GOLANGCI_LINT_VERSION: v2.0
124124
125125
jobs:
126126
detect-modules:
@@ -147,7 +147,7 @@ jobs:
147147
with:
148148
go-version: ${{ env.GO_VERSION }}
149149
- name: golangci-lint ${{ matrix.modules }}
150-
uses: golangci/golangci-lint-action@v6
150+
uses: golangci/golangci-lint-action@v7
151151
with:
152152
version: ${{ env.GOLANGCI_LINT_VERSION }}
153153
working-directory: ${{ matrix.modules }}
@@ -179,7 +179,7 @@ jobs:
179179
with:
180180
os: ${{ matrix.os }}
181181
go-version: ${{ matrix.go-version }}
182-
golangci-lint-version: v1.64
182+
golangci-lint-version: v2.0
183183
```
184184

185185
```yaml
@@ -201,7 +201,7 @@ on:
201201
golangci-lint-version:
202202
description: 'Golangci-lint version'
203203
type: string
204-
default: 'v1.64'
204+
default: 'v2.0'
205205
206206
jobs:
207207
detect-modules:
@@ -229,7 +229,7 @@ jobs:
229229
with:
230230
go-version: ${{ inputs.go-version }}
231231
- name: golangci-lint ${{ matrix.modules }}
232-
uses: golangci/golangci-lint-action@v6
232+
uses: golangci/golangci-lint-action@v7
233233
with:
234234
version: ${{ inputs.golangci-lint-version }}
235235
working-directory: ${{ matrix.modules }}
@@ -245,6 +245,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t
245245

246246
## Compatibility
247247

248+
* `v7.0.0` supports golangci-lint v2 only.
248249
* `v6.0.0+` removes `annotations` option, removes the default output format (`github-actions`).
249250
* `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`.
250251
* `v4.0.0+` requires an explicit `actions/setup-go` installation step before using this action: `uses: actions/setup-go@v5`.
@@ -262,17 +263,17 @@ You will also likely need to add the following `.gitattributes` file to ensure t
262263
The version of golangci-lint to use.
263264

264265
When `install-mode` is:
265-
* `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
266-
* `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit.
266+
* `binary` (default): the value can be v2.3 or v2.3.4 or `latest` to use the latest version.
267+
* `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
267268
* `none`: the value is ignored.
268269

269270
<details>
270271
<summary>Example</summary>
271272

272273
```yml
273-
uses: golangci/golangci-lint-action@v6
274+
uses: golangci/golangci-lint-action@v7
274275
with:
275-
version: v1.58
276+
version: v2.0
276277
# ...
277278
```
278279

@@ -290,7 +291,7 @@ The default value is `binary`.
290291
<summary>Example</summary>
291292

292293
```yml
293-
uses: golangci/golangci-lint-action@v6
294+
uses: golangci/golangci-lint-action@v7
294295
with:
295296
install-mode: "goinstall"
296297
# ...
@@ -310,7 +311,7 @@ By default, it uses the `github.token` from the action.
310311
<summary>Example</summary>
311312

312313
```yml
313-
uses: golangci/golangci-lint-action@v6
314+
uses: golangci/golangci-lint-action@v7
314315
with:
315316
github-token: xxx
316317
# ...
@@ -333,7 +334,7 @@ The JSONSchema used to validate the configuration depends on the version of gola
333334
<summary>Example</summary>
334335

335336
```yml
336-
uses: golangci/golangci-lint-action@v6
337+
uses: golangci/golangci-lint-action@v7
337338
with:
338339
verify: false
339340
# ...
@@ -358,7 +359,7 @@ The default value is `false`.
358359
<summary>Example</summary>
359360

360361
```yml
361-
uses: golangci/golangci-lint-action@v6
362+
uses: golangci/golangci-lint-action@v7
362363
with:
363364
only-new-issues: true
364365
# ...
@@ -376,7 +377,7 @@ Working directory, useful for monorepos.
376377
<summary>Example</summary>
377378

378379
```yml
379-
uses: golangci/golangci-lint-action@v6
380+
uses: golangci/golangci-lint-action@v7
380381
with:
381382
working-directory: somedir
382383
# ...
@@ -397,9 +398,9 @@ The location of the configuration file can be changed by using `--config=`
397398
<summary>Example</summary>
398399

399400
```yml
400-
uses: golangci/golangci-lint-action@v6
401+
uses: golangci/golangci-lint-action@v7
401402
with:
402-
args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
403+
args: --config=/my/path/.golangci.yml --issues-exit-code=0
403404
# ...
404405
```
405406

@@ -411,7 +412,7 @@ with:
411412

412413
Force the usage of the embedded problem matchers.
413414

414-
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`).
415+
By default, the [problem matcher of Go (`actions/setup-go`)](https://github.com/actions/setup-go/blob/main/matchers.json) already handles the default golangci-lint output (`text`).
415416

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

@@ -423,7 +424,7 @@ The default value is `false`.
423424
<summary>Example</summary>
424425

425426
```yml
426-
uses: golangci/golangci-lint-action@v6
427+
uses: golangci/golangci-lint-action@v7
427428
with:
428429
problem-matchers: true
429430
# ...
@@ -444,7 +445,7 @@ The default value is `false`.
444445
<summary>Example</summary>
445446

446447
```yml
447-
uses: golangci/golangci-lint-action@v6
448+
uses: golangci/golangci-lint-action@v7
448449
with:
449450
skip-cache: true
450451
# ...
@@ -464,7 +465,7 @@ The default value is `false`.
464465
<summary>Example</summary>
465466

466467
```yml
467-
uses: golangci/golangci-lint-action@v6
468+
uses: golangci/golangci-lint-action@v7
468469
with:
469470
skip-save-cache: true
470471
# ...
@@ -486,7 +487,7 @@ If set the number is `<= 0`, the cache will be always invalidate (Not recommende
486487
<summary>Example</summary>
487488

488489
```yml
489-
uses: golangci/golangci-lint-action@v6
490+
uses: golangci/golangci-lint-action@v7
490491
with:
491492
cache-invalidation-interval: 15
492493
# ...
@@ -517,7 +518,7 @@ permissions:
517518
checks: write
518519
```
519520
520-
For annotations to work use the default `colored-line-number` output and either use `actions/setup-go` in the job or enable the internal [problem matchers](#problem-matchers).
521+
For annotations to work use the default format output (`text`) and either use `actions/setup-go` in the job or enable the internal [problem matchers](#problem-matchers).
521522

522523
## Performance
523524

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ inputs:
77
description: |
88
The version of golangci-lint to use.
99
When `install-mode` is:
10-
- `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
11-
- `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit.
10+
- `binary` (default): the value can be v2.3 or v2.3.4 or `latest` to use the latest version.
11+
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
1212
- `none`: the value is ignored.
1313
required: false
1414
install-mode:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/golangci/golangci-lint-action
22

3-
go 1.14
3+
go 1.23

sample-go-mod/.golangci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
version: "2"
2+
13
output:
24
show-stats: true
3-
sort-results: true
45
sort-order:
6+
- file
57
- linter
6-
- file

sample-go-mod/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module sample
22

33
go 1.22.1
44

5-
require github.com/golangci/golangci-lint v1.60.1
5+
require github.com/golangci/golangci-lint/v2 v2.0.0
66

77
require (
88
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect

sample-go-mod/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
package main
44

55
import (
6-
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
6+
_ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint"
77
)

sample-go-tool/.golangci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
version: "2"
2+
13
output:
24
show-stats: true
3-
sort-results: true
45
sort-order:
6+
- file
57
- linter
6-
- file

sample-go-tool/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24
44

55
toolchain go1.24.0
66

7-
tool github.com/golangci/golangci-lint/cmd/golangci-lint
7+
tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint
88

99
require (
1010
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
@@ -68,7 +68,7 @@ require (
6868
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
6969
github.com/golangci/go-printf-func-name v0.1.0 // indirect
7070
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
71-
github.com/golangci/golangci-lint v1.64.4 // indirect
71+
github.com/golangci/golangci-lint/v2 v2.0.0 // indirect
7272
github.com/golangci/misspell v0.6.0 // indirect
7373
github.com/golangci/plugin-module-register v0.1.1 // indirect
7474
github.com/golangci/revgrep v0.8.0 // indirect

src/install.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,14 @@ async function goInstall(versionInfo: VersionInfo): Promise<string> {
8484

8585
const options: ExecOptions = { env: { ...process.env, CGO_ENABLED: "1" } }
8686

87-
// TODO(ldez): it should be updated for v2.
8887
const exres = await execShellCommand(
89-
`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`,
88+
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
9089
options
9190
)
9291
printOutput(exres)
9392

94-
// TODO(ldez): it should be updated for v2.
9593
const res = await execShellCommand(
96-
`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`,
94+
`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
9795
options
9896
)
9997
printOutput(res)

src/run.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
5151
printOutput(res)
5252
}
5353

54-
let userArgs = core.getInput(`args`)
54+
const userArgs = core.getInput(`args`)
5555
const addedArgs: string[] = []
5656

5757
const userArgsList = userArgs
@@ -76,23 +76,13 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
7676
}
7777
}
7878

79-
const formats = (userArgsMap.get("out-format") || "")
80-
.trim()
81-
.split(",")
82-
.filter((f) => f.length > 0)
83-
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
84-
.join(",")
85-
86-
if (formats) {
87-
// Adds formats but without `github-actions` format.
88-
addedArgs.push(`--out-format=${formats}`)
89-
}
90-
91-
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
92-
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
93-
9479
if (isOnlyNewIssues()) {
95-
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
80+
if (
81+
userArgNames.has(`new`) ||
82+
userArgNames.has(`new-from-rev`) ||
83+
userArgNames.has(`new-from-patch`) ||
84+
userArgNames.has(`new-from-merge-base`)
85+
) {
9686
throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
9787
}
9888

@@ -110,6 +100,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
110100
// Override config values.
111101
addedArgs.push(`--new=false`)
112102
addedArgs.push(`--new-from-rev=`)
103+
addedArgs.push(`--new-from-merge-base=`)
113104
}
114105
break
115106
case `merge_group`:
@@ -118,6 +109,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
118109
// Override config values.
119110
addedArgs.push(`--new=false`)
120111
addedArgs.push(`--new-from-patch=`)
112+
addedArgs.push(`--new-from-merge-base=`)
121113
break
122114
default:
123115
break
@@ -150,7 +142,6 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
150142
core.info(`golangci-lint found no issues`)
151143
} catch (exc) {
152144
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
153-
// TODO: support reviewdog or leaving comments by GitHub API.
154145
printOutput(exc)
155146

156147
if (exc.code === 1) {

0 commit comments

Comments
 (0)