-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (200 loc) · 7.89 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# DOCS: https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: kama ci
on:
pull_request:
push:
branches:
- main
jobs:
check_release_notes:
name: check_release_notes
timeout-minutes: 1
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4 # since v4, it added cache by default.
with:
go-version: ${{ matrix.go-version }}
- name: checkout main branch too. # so that it is also available for diff operations
uses: actions/checkout@v3
with:
ref: main
- name: Check out code into the Go module directory
uses: actions/checkout@v3
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
- name: check if changes have release notes
if: github.ref != 'refs/heads/main'
env:
GIT_BRANCH: ${{ github.ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
run: |
printf "GIT_BRANCH: $GIT_BRANCH \n"
printf "GITHUB_HEAD_REF: $GITHUB_HEAD_REF \n"
printf "GITHUB_BASE_REF: $GITHUB_BASE_REF \n"
printf "list git branches: \n"
git branch --list --all
if [[ "$GIT_BRANCH" == "refs/heads/main" ]]
then
printf "\n $GIT_BRANCH branch, ignoring check for relese notes \n"
elif [[ "$GIT_BRANCH" == *"refs/tags/"* ]]
then
printf "\n $GIT_BRANCH branch, ignoring check for relese notes \n"
else
ChangedFiles=`git diff --name-only remotes/origin/main`
echo $ChangedFiles
case "$ChangedFiles" in
*CHANGELOG.*)
printf "\n Thanks, your commits include update to release notes. \n";;
*)
printf "\n You should add release notes to CHANGELOG.md \n" && exit 77;;
esac
fi
run_tests:
name: run_tests
timeout-minutes: 7
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: tests and benchmarks
run: |
go test -timeout 1m -race -run=XXXX -bench=. ./...
go test -timeout 4m -race ./...
- name: test coverage
run: |
set -x
# check integrity of codecov
curl -s https://codecov.io/bash > codecov;
VERSION=$(grep -o 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2);
shasum --algorithm 512 --check <(curl -s "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA512SUM" | grep codecov)
rm -rf codecov
go test -timeout 4m -race -cover -coverprofile=coverage.out ./... && bash <(curl -s https://codecov.io/bash)
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out
run_analysis:
name: run_analysis
timeout-minutes: 5
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: install apt and pip deps
run: |
pwd; ls -lsha
sudo apt-get -y update
sudo apt -y install wget
- name: install tools
run: |
set -x
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/securego/gosec/cmd/gosec@latest
go install github.com/orijtech/structslop/cmd/structslop@latest
go install github.com/orijtech/httperroryzer/cmd/httperroryzer@latest
go install golang.org/x/tools/cmd/stress@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
go install github.com/kisielk/errcheck@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
/home/runner/go/bin/staticcheck -version
env:
SOME_ENV_VAR: '2020.1.6'
- name: static analysis
run: |
set -x
diff <(gofmt -d .) <(printf "")
go vet -all ./...
go vet -vettool=/home/runner/go/bin/shadow -strict ./...
/home/runner/go/bin/staticcheck -tests -go 1.20 ./...
# /home/runner/go/bin/gosec ./... # does not yet support generics.
# /home/runner/go/bin/structslop ./... # does not yet support generics.
# /home/runner/go/bin/httperroryzer ./... # re-enable after https://github.com/komuw/kama/issues/63
# see: https://github.com/golang/go/commit/a98589711da5e9d935e8d690cfca92892e86d557
/home/runner/go/bin/errcheck -ignoregenerated -ignoretests -asserts ./...
# dont use golangci-lint
# see: https://twitter.com/dominikhonnef/status/1394766501157167112
#
# In our case we need to use it so that we can be able to use `nolint:gocritic`
# Since `go-ruleguard` does not have a way to ignore per line, see: https://github.com/quasilyte/go-ruleguard/issues/248 .
#
wget -nc --output-document=/tmp/semgrep-go.zip https://github.com/dgryski/semgrep-go/archive/refs/heads/master.zip
unzip -o /tmp/semgrep-go.zip -d /tmp/semgrep-go
go get github.com/quasilyte/go-ruleguard/dsl
golangci-lint run --config .golangci.yml ./...
go mod tidy
# deadlock detection
# https://github.com/cockroachdb/cockroach/issues/7972
go get github.com/sasha-s/go-deadlock
find . -name "*.go" | xargs -n 1 sed -i.backup 's/sync.RWMutex/deadlock.RWMutex/'
find . -name "*.go" | xargs -n 1 sed -i.backup 's/sync.Mutex/deadlock.Mutex/'
find . -name '*.backup' -delete
/home/runner/go/bin/goimports -w .
go test -timeout 4m -race ./...
go mod tidy
# error shadowing
num_err_shadows=$(grep -irSn 'err = ' *.go | wc -l | tr -d ' ')
if [ "$num_err_shadows" != "0" ]; then
printf "\n\t fix error shadowing \n" && \
grep -irSn 'err = ' *.go
exit 77
fi
# TODO: add https://github.com/system-pclub/GCatch
do_acceptance:
name: do_acceptance
timeout-minutes: 3
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: dummy run
run: |
go build -trimpath -race -o kama cmd/kama/main.go
./kama -h
# run_stress_test:
# name: run_stress_test
# timeout-minutes: 2
# strategy:
# matrix:
# go-version: ['>=1.22.0']
# platform: [ubuntu-22.04]
# runs-on: ${{ matrix.platform }}
# steps:
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: ${{ matrix.go-version }}
# - name: Check out code into the Go module directory
# uses: actions/checkout@v3
# - name: stress test
# run: |
# go install golang.org/x/tools/cmd/stress@latest
# go test -o kama.test -c -race
# /home/runner/go/bin/stress -timeout 10s ./kama.test