forked from FerretDB/FerretDB
405 lines (333 loc) · 12 KB
/
go.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
---
name: Go
on:
pull_request:
types:
- unlabeled # if GitHub Actions stuck, add and remove "not ready" label to force rebuild
- opened
- reopened
- synchronize
push:
branches:
- main
- main-*
- releases/*
schedule:
- cron: "12 0 * * *"
env:
GOPATH: /home/runner/go
GOCACHE: /home/runner/go/cache
GOLANGCI_LINT_CACHE: /home/runner/go/cache/lint
GOMODCACHE: /home/runner/go/mod
GOPROXY: https://proxy.golang.org
GOTOOLCHAIN: local
jobs:
short-test:
name: Short test
runs-on: ubuntu-22.04
timeout-minutes: 15
# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-short-test-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: short-test
- name: Install Task
run: go generate -x
working-directory: tools
- name: Run init
run: bin/task init
- name: Run short unit tests
run: bin/task test-unit-short TEST_TIMEOUT=10m
env:
GOFLAGS: ${{ runner.debug == '1' && '-v' || '' }}
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
test:
name: Test
runs-on: ubuntu-22.04
timeout-minutes: 15
# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-test-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: test
- name: Install Task
run: go generate -x
working-directory: tools
- name: Start environment
run: bin/task env-up-detach
- name: Run init
run: bin/task init
- name: Regenerate and reformat
run: bin/task gen
- name: Build bin/ferretdb
run: bin/task build-host
- name: Wait for and setup environment
run: bin/task env-setup
- name: Run unit tests
run: bin/task test-unit TEST_TIMEOUT=10m
env:
GOFLAGS: ${{ runner.debug == '1' && '-v' || '' }}
# The token is not required but should make uploads more stable.
# If secrets are unavailable (for example, for a pull request from a fork), it fallbacks to the tokenless uploads.
#
# Unfortunately, it seems that tokenless uploads fail too often.
# See https://github.com/codecov/codecov-action/issues/837.
#
# We also can't use ${{ vars.CODECOV_TOKEN }}: https://github.com/orgs/community/discussions/44322
- name: Upload coverage information to codecov
if: always()
uses: codecov/codecov-action@v4
with:
token: 22159d7c-856d-4fe9-8fdb-5d9ecff35514
files: ./cover.txt
flags: unit
fail_ci_if_error: true
verbose: true
- name: Upload coverage information to coveralls
uses: coverallsapp/github-action@v2
with:
file: ./cover.txt
flag-name: unit
parallel: true
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
integration:
# job name must be unique; make it unique and nice
name: ${{ matrix.task }} ${{ matrix.shard_index }}/${{ matrix.shard_total }}
# Do not run this job in parallel for any PR change or branch push
# to save some resources.
concurrency:
group: ${{ github.workflow }}-integration-${{ matrix.task }}-${{ matrix.shard_index }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
strategy:
fail-fast: false
matrix:
task: [postgresql, sqlite]
shard_index: [1, 2, 3]
shard_total: [3]
include:
- { task: "mongodb", shard_index: 1, shard_total: 1 }
uses: ./.github/workflows/_integration.yml
with:
task: ${{ matrix.task }}
shard_index: ${{ matrix.shard_index }}
shard_total: ${{ matrix.shard_total }}
coveralls: true
# https://github.com/lemurheavy/coveralls-public/issues/1636
submit-coveralls:
name: Submit final coveralls report
runs-on: ubuntu-22.04
needs: [test, integration]
if: always() && (github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready'))
steps:
- name: Submit coveralls
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
env-data:
name: env-data
runs-on: ubuntu-22.04
timeout-minutes: 10
# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-env-data-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: env-data
- name: Install Task
run: go generate -x
working-directory: tools
- name: Start environment
run: bin/task env-up-detach
- name: Run init
run: bin/task init
- name: Wait for and setup environment
run: bin/task env-setup
- name: Run env-data
run: bin/task env-data
env:
GOFLAGS: ${{ runner.debug == '1' && '-v' || '' }}
golangci-lint:
name: golangci-lint
runs-on: ubuntu-22.04
timeout-minutes: 10
# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-golangci-lint-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for `golangci-lint run --new` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: lint
- name: Run linters
uses: FerretDB/github-actions/linters@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
fuzz-short:
name: Fuzz short
runs-on: ubuntu-22.04
timeout-minutes: 15
# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-fuzz-short-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
path: source
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: fuzz
- name: Install Task
run: go generate -x
working-directory: source/tools
# TODO https://github.com/FerretDB/github-actions/issues/211
# Use deploy key instead of Personal Access Token (PAT) to limit access to one repository.
# If secrets are not available (for example, for a pull request from a fork), GITHUB_TOKEN PAT is used automatically.
- name: Checkout collected fuzz corpus
uses: actions/checkout@v4
with:
repository: FerretDB/fuzz-corpus
ssh-key: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
path: fuzz-corpus
fetch-depth: 0 # for commit and push to work
- name: Setup corpus
run: bin/task fuzz-corpus
working-directory: source
# precompile tests with unset GOMAXPROCS
- name: Init fuzzers
run: bin/task fuzz-init
working-directory: source
# TODO https://github.com/FerretDB/FerretDB/issues/238
# TODO https://github.com/FerretDB/FerretDB/issues/344
- name: Fuzz
run: bin/task fuzz FUZZ_TIME=1m
working-directory: source
env:
GOMAXPROCS: 1 # otherwise, oom-killer kills fuzzer too often
- name: Collect corpus
if: always()
run: bin/task fuzz-corpus
working-directory: source
# `secrets` are not supported in `if`, so we have to do this trick with environment variable:
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
# https://github.com/actions/runner/issues/520
- name: Push corpus if possible
if: always() && env.KEY != ''
env:
KEY: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
run: |
set -x
git config user.name ferretdb-bot
git config user.email ferretdb-bot@ferretdb.io
git add --all .
git diff-index -p HEAD
git diff-index --quiet HEAD || git commit --message 'Update corpus'
git fetch
git rebase origin/main
git push
working-directory: fuzz-corpus
- name: Compress corpus before upload
if: failure() || env.KEY == ''
env:
KEY: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
run: zip -r -q -9 fuzz-corpus.zip fuzz-corpus
- name: Upload corpus on failure or if push is not possible
if: failure() || env.KEY == ''
env:
KEY: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
uses: actions/upload-artifact@v4
with:
name: fuzz-corpus
path: fuzz-corpus.zip
retention-days: 1
if-no-files-found: error
- name: Collect Linux logs
if: failure()
run: |
mkdir -p /tmp/logs
ls -al /var/log/
sudo cp /var/log/syslog /tmp/logs/
sudo free > /tmp/logs/free.txt
sudo chmod 0666 /tmp/logs/*
working-directory: source
- name: Compress Linux logs before upload
if: failure()
run: zip -r -q -9 linux-logs.zip /tmp/logs
- name: Upload Linux logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: linux-logs
path: linux-logs.zip
retention-days: 1
if-no-files-found: error
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
working-directory: source