-
Notifications
You must be signed in to change notification settings - Fork 4
279 lines (248 loc) · 10.1 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# DOCS:
# 1. https://help.github.com/en/articles/workflow-syntax-for-github-actions
# 2. https://github.com/mvdan/github-actions-golang/issues/22
# 3. https://github.com/stellar/go/blob/master/.github/actions/setup-go/action.yml
# 4. https://github.com/stellar/go/blob/master/.github/workflows/go.yml
# 5. https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
# 6. https://github.com/golang/go/issues/58571
name: ong ci
on:
pull_request:
push:
branches:
- main
jobs:
check_release_notes:
name: check_release_notes
timeout-minutes: 1
strategy:
matrix:
go-version: ['>=1.23.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
# checkout main branch and the current branch so that we are able to do diff operations.
- name: checkout main branch too.
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.23.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4 # since v4, it added cache by default.
with:
go-version: ${{ matrix.go-version }}
- name: tests and benchmarks
run: |
ulimit -a
env
set -x
go test -timeout 1m -race -run=XXXX -bench=. ./...
go test -timeout 4m -race -cover -coverprofile=coverage.out -shuffle on -count=2 ./...
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out
wget -nc --output-document=/tmp/codecov https://github.com/codecov/uploader/releases/download/v0.3.5/codecov-linux
chmod +x /tmp/codecov
/tmp/codecov
env:
ONG_RUNNING_IN_TESTS: 'YES'
run_analysis:
name: run_analysis
timeout-minutes: 8
strategy:
matrix:
go-version: ['>=1.23.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: install apt and pip deps
run: |
pwd; ls -lsha
sudo apt -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/quasilyte/go-ruleguard/cmd/ruleguard@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 golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest
go install github.com/kisielk/errcheck@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install mvdan.cc/gofumpt@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
go install github.com/mdempsky/unconvert@latest
go install github.com/zricethezav/gitleaks/v8@latest
go install gvisor.dev/gvisor/tools/checklocks/cmd/checklocks@latest
/home/runner/go/bin/staticcheck -version
env:
SOME_ENV_VAR: '2020.1.6'
- name: static analysis
run: |
set -x
diff <(gofmt -d .) <(printf "")
diff <(gofumpt -extra -w -d .) <(printf "")
diff <(goimports -d .) <(printf "")
go vet -all ./...
go vet -vettool=/home/runner/go/bin/shadow -strict ./...
go vet -vettool=/home/runner/go/bin/nilness -test ./...
# /home/runner/go/bin/checklocks -test=false ./...
/home/runner/go/bin/staticcheck -tests ./...
/home/runner/go/bin/govulncheck ./...
# /home/runner/go/bin/gosec ./... # does not seem to work with Go1.21
# /home/runner/go/bin/structslop ./... # needed once in a while.
# /home/runner/go/bin/httperroryzer ./... # re-enable after https://github.com/komuw/ong/issues/410
# see: https://github.com/golang/go/commit/a98589711da5e9d935e8d690cfca92892e86d557
/home/runner/go/bin/errcheck -ignoregenerated -ignoretests -asserts ./...
/home/runner/go/bin/unconvert -v ./...
/home/runner/go/bin/gitleaks detect . -v --no-git --baseline-path .gitleaksignore
# To create the gitleaksignore file, run;
# rm -rf .gitleaksignore; gitleaks detect . --no-git --report-path .gitleaksignore
# 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` in the errors package.
#
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
python -m venv /tmp/.venv
. /tmp/.venv/bin/activate
python -m pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org semgrep
semgrep -f /tmp/semgrep-go/semgrep-go-master/ --error .
deactivate
# An alternative it to do:
# semgrep -f https://semgrep.dev/r/dgryski.semgrep-go --exclude="*_test.go" .
# deadlock detection
# https://github.com/cockroachdb/cockroach/issues/7972
go get -u 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
# TODO: add https://github.com/system-pclub/GCatch
env:
ONG_RUNNING_IN_TESTS: 'YES'
# https://go.dev/testing/coverage/
integration_test_coverage:
name: integration_test_coverage
timeout-minutes: 3
strategy:
matrix:
go-version: ['>=1.23.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: whole program coverage
run: |
set -x
pwd; ls -lsha
sudo apt -y update
sudo apt -y install libnss3-tools jq # certutil
mkdir -p coverage/
rm -rf coverage/* ongExample
go build -cover -o ongExample github.com/komuw/ong/example
GOCOVERDIR=coverage/ ./ongExample > logs_one.json 2>&1 &
sleep 10 && kill -15 $(pidof ongExample)
{ # try
kill -9 $(pidof ongExample)
} || { # catch
echo -n ""
}
cat logs_one.json
GOCOVERDIR=coverage/ ./ongExample > logs_two.json 2>&1 &
sleep 10
cat logs_two.json
ls -lsha coverage/
ss --listening --processes --query=tcp,udp
go test -timeout 4m -race --tags=integration github.com/komuw/ong/example -v
kill -15 $(pidof ongExample)
{ # try
kill -9 $(pidof ongExample)
} || { # catch
echo -n ""
}
ls -lsha coverage/
go tool covdata percent -i=coverage
env:
ONG_RUNNING_IN_TESTS: 'YES'
ONG_EXAMPLE_TESTS_BASIC_AUTH: "super-h@rd-Pas1word" # Ought to be same value as used in /example/main.go
# run_stress_test:
# name: run_stress_test
# timeout-minutes: 2
# strategy:
# matrix:
# go-version: ['>=1.23.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: stress test
# run: |
# go install golang.org/x/tools/cmd/stress@latest
# go test -o ong.test -c -race
# /home/runner/go/bin/stress -timeout 10s ./ong.test