Skip to content

Commit b291e34

Browse files
authored
add lint workflow and fix lint issue (#212)
total 394 lint issues discovered by the tool. 95% fix is done by copilot , including several bugs found by lint 1. Run method in actionsrunner/runner.go actionsrunner/runner.go:147:3: deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop (gocritic) defer cancelJobListening() 2. io.Read/Write err not check: ignore most by AI but manually add logging at several places 3. fix another 39 errors by upgrading golangci-lint Signed-off-by: Leslie Qi Wang <qiwa@pensando.io>
1 parent d77360e commit b291e34

34 files changed

Lines changed: 1618 additions & 1094 deletions

.github/workflows/lint.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Go Lint
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.21'
22+
23+
- name: Cache Go modules
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.cache/go-build
28+
~/go/pkg/mod
29+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
30+
restore-keys: |
31+
${{ runner.os }}-go-
32+
33+
- name: Download dependencies
34+
run: go mod download
35+
36+
- name: Run golangci-lint
37+
uses: golangci/golangci-lint-action@v4
38+
with:
39+
version: latest
40+
args: --timeout=5m

.golangci.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
run:
2+
timeout: 5m
3+
go: '1.21'
4+
5+
linters-settings:
6+
govet:
7+
enable:
8+
- shadow
9+
revive:
10+
min-confidence: 0.8
11+
gocyclo:
12+
min-complexity: 15
13+
dupl:
14+
threshold: 100
15+
goconst:
16+
min-len: 2
17+
min-occurrences: 2
18+
misspell:
19+
locale: US
20+
lll:
21+
line-length: 140
22+
goimports:
23+
local-prefixes: github.com/ChristopherHX/github-act-runner
24+
gocritic:
25+
enabled-tags:
26+
- diagnostic
27+
- experimental
28+
- opinionated
29+
- performance
30+
- style
31+
disabled-checks:
32+
- dupImport # https://github.com/go-critic/go-critic/issues/845
33+
- ifElseChain
34+
- octalLiteral
35+
- whyNoLint
36+
- wrapperFunc
37+
38+
linters:
39+
enable:
40+
- bodyclose
41+
# - depguard # Disabled for now as it's too restrictive
42+
- dogsled
43+
- dupl
44+
- errcheck
45+
- copyloopvar # replaces exportloopref for Go 1.22+
46+
- exhaustive
47+
- goconst
48+
- gocritic
49+
- gofmt
50+
- goimports
51+
- revive # replaces golint
52+
- mnd # replaces gomnd
53+
- goprintffuncname
54+
- gosec
55+
- gosimple
56+
- govet
57+
- ineffassign
58+
- lll
59+
- misspell
60+
- nakedret
61+
- noctx
62+
- nolintlint
63+
- rowserrcheck
64+
- staticcheck
65+
- stylecheck
66+
- typecheck
67+
- unconvert
68+
- unparam
69+
- unused
70+
- whitespace
71+
72+
issues:
73+
exclude-rules:
74+
- path: _test\.go
75+
linters:
76+
- mnd
77+
- gocritic
78+
- gosec
79+
- path: main\.go
80+
linters:
81+
- mnd
82+
- path: protocol/
83+
linters:
84+
- revive # Protocol has many generated-like structs
85+
- text: "weak cryptographic primitive"
86+
linters:
87+
- gosec
88+
- text: "Use of weak random number generator"
89+
linters:
90+
- gosec
91+
- text: "at least one file in a package should have a package comment"
92+
linters:
93+
- stylecheck
94+
- text: "should have a package comment"
95+
linters:
96+
- stylecheck
97+
- text: "package-comments: should have a package comment"
98+
linters:
99+
- revive
100+
- text: "exported function .* should have comment or be unexported"
101+
linters:
102+
- revive
103+
- text: "exported method .* should have comment or be unexported"
104+
linters:
105+
- revive
106+
- text: "exported type .* should have comment or be unexported"
107+
linters:
108+
- revive
109+
- text: "exported var .* should have comment or be unexported"
110+
linters:
111+
- revive
112+
113+
exclude-use-default: false
114+
max-issues-per-linter: 0
115+
max-same-issues: 0

actionsdotnetactcompat/act_runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ type ActRunner struct {
99
actionsrunner.WorkerRunnerEnvironment
1010
}
1111

12-
func (arunner *ActRunner) ExecWorker(run *actionsrunner.RunRunner, wc actionsrunner.WorkerContext, jobreq *protocol.AgentJobRequestMessage, src []byte) error {
13-
if len(arunner.WorkerArgs) <= 0 {
12+
func (arunner *ActRunner) ExecWorker(run *actionsrunner.RunRunner, wc actionsrunner.WorkerContext,
13+
jobreq *protocol.AgentJobRequestMessage, src []byte) error {
14+
if len(arunner.WorkerArgs) == 0 {
1415
ExecWorker(jobreq, wc)
1516
return nil
1617
}

0 commit comments

Comments
 (0)