Skip to content

Commit d5ea73e

Browse files
committed
add lint workflow and fix lint issue
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 Signed-off-by: Leslie Qi Wang <qiwa@pensando.io>
1 parent d77360e commit d5ea73e

34 files changed

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