Skip to content

Commit f80e569

Browse files
committed
ci: Refactor CI workflow and split CI into two parts with golangci-lint-action
Signed-off-by: Eric Zhao <[email protected]>
1 parent 822406f commit f80e569

File tree

2 files changed

+97
-57
lines changed

2 files changed

+97
-57
lines changed

.github/workflows/go.yml

+68-57
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,89 @@ name: CI
22

33
on:
44
push:
5-
branches: master
5+
branches: [ "main", "master" ]
66
pull_request:
7-
branches: "*"
7+
branches: [ "*" ]
88

99
jobs:
1010

11+
lint:
12+
name: Lint check
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version: 1.18
20+
21+
- name: Check out code into the Go module directory
22+
uses: actions/checkout@v3
23+
24+
- name: Golangci Lint
25+
# https://golangci-lint.run/
26+
uses: golangci/golangci-lint-action@v3
27+
with:
28+
version: latest
29+
args: "--out-${NO_FUTURE}format colored-line-number"
30+
1131
build:
12-
name: ${{ matrix.os }} - Go ${{ matrix.go_version }}
32+
name: Build and test - Go ${{ matrix.go_version }}
1333
runs-on: ubuntu-latest
1434
strategy:
15-
# If you want to matrix build , you can append the following list.
35+
# If you want to matrix build , you can append the following list.
1636
matrix:
1737
go_version:
18-
- 1.13
19-
- 1.14
38+
- 1.16
39+
- 1.18
40+
- 1.19
2041
os:
2142
- ubuntu-latest
2243

2344
steps:
2445

25-
- name: Set up Go ${{ matrix.go_version }}
26-
uses: actions/setup-go@v2
27-
with:
28-
go-version: ${{ matrix.go_version }}
29-
id: go
30-
31-
- name: Check out code into the Go module directory
32-
uses: actions/checkout@v2
33-
34-
- name: Cache build dependence
35-
uses: actions/cache@v2
36-
with:
37-
# Cache
38-
path: ~/go/pkg/mod
39-
# Cache key
40-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
41-
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
42-
restore-keys: ${{ runner.os }}-go-
46+
- name: Set up Go ${{ matrix.go_version }}
47+
uses: actions/setup-go@v3
48+
with:
49+
go-version: ${{ matrix.go_version }}
50+
id: go
4351

44-
- name: Install goimports
45-
run: go get golang.org/x/tools/cmd/goimports
52+
- name: Check out code into the Go module directory
53+
uses: actions/checkout@v3
4654

47-
- name: Install go ci lint
48-
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
55+
- name: Cache build dependence
56+
uses: actions/cache@v3
57+
with:
58+
# Cache
59+
path: ~/go/pkg/mod
60+
# Cache key
61+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
62+
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
63+
restore-keys: ${{ runner.os }}-go-
4964

50-
- name: Run Linter
51-
run: golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell
65+
- name: Test
66+
run: |
67+
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
68+
cd ./pkg/datasource/consul
69+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
70+
cd ../etcdv3
71+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
72+
cd ../k8s
73+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
74+
cd ../nacos
75+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
76+
cd ../apollo
77+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
78+
cd ../../adapters/echo
79+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
80+
cd ../gear
81+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
82+
cd ../gin
83+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
84+
cd ../grpc
85+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
86+
cd ../micro
87+
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
5288
53-
- name: Test
54-
run: |
55-
diff -u <(echo -n) <(gofmt -d -s .)
56-
diff -u <(echo -n) <(goimports -d .)
57-
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
58-
cd ./pkg/datasource/consul
59-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
60-
cd ../etcdv3
61-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
62-
cd ../k8s
63-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
64-
cd ../nacos
65-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
66-
cd ../apollo
67-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
68-
cd ../../adapters/echo
69-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
70-
cd ../gear
71-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
72-
cd ../gin
73-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
74-
cd ../grpc
75-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
76-
cd ../micro
77-
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic
78-
- name: Coverage
79-
run: bash <(curl -s https://codecov.io/bash)
89+
- name: Coverage
90+
run: bash <(curl -s https://codecov.io/bash)

.golangci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Options for analysis running.
2+
run:
3+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
4+
skip-dirs-use-default: true
5+
skip-dirs:
6+
- example
7+
skip-files:
8+
- ".*\\.pb\\.go$"
9+
# output configuration options
10+
output:
11+
format: colored-line-number
12+
# Refer to https://golangci-lint.run/usage/linters
13+
linters-settings:
14+
govet:
15+
# Disable analyzers by name.
16+
# Run `go tool vet help` to see all analyzers.
17+
disable:
18+
- stdmethods
19+
linters:
20+
disable-all: true
21+
enable:
22+
- goimports
23+
- gofmt
24+
- misspell
25+
- govet
26+
- ineffassign
27+
- staticcheck
28+
issues:
29+
exclude-use-default: true

0 commit comments

Comments
 (0)