-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
476 lines (441 loc) · 11.7 KB
/
.gitlab-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
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.10"
stages:
- setup
- static_analysis
- test
- build
- integration_test
- security_analysis
- publish
variables:
POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/poetry"
.poetry cache:
stage: setup
script:
- time poetry install --no-ansi --sync
cache:
key:
prefix: "py"
files:
- poetry.lock
policy: pull-push
paths:
- .cache/poetry/
except:
- main
- tags
poetry cache py3.8:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8"
cache:
key:
prefix: "py38"
files:
- poetry.lock
poetry cache py3.9:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.9"
cache:
key:
prefix: "py39"
files:
- poetry.lock
poetry cache py3.10:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.10"
script:
# we use this cache to run all checks, so install everything
- time poetry install --no-ansi --sync --with tests --with lint --with dev
cache:
key:
prefix: "py310"
files:
- poetry.lock
poetry cache py3.11:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.11"
cache:
key:
prefix: "py311"
files:
- poetry.lock
poetry cache py3.12:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.12"
cache:
key:
prefix: "py312"
files:
- poetry.lock
poetry cache py3.13-pre:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.13-pre"
script:
# ToDo: there's no blake3 wheel yet for 3.13, remove this when there's one.
# Check if we need to install everything or just check for changes in the package lock
- set -euo pipefail
- if poetry env info -p; then
echo "We have a cached venv";
else
echo "No cache, installing everything...";
apt-get update && apt-get install -y curl;
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh;
sh rustup.sh -v -y;
source $HOME/.cargo/env;
fi;
- time poetry install --no-ansi --sync
allow_failure: true
cache:
key:
prefix: "py313pre"
files:
- poetry.lock
.poetry cache pypy:
extends: .poetry cache
script:
# ToDo: there's no blake3 wheel yet for PyPy, remove this when there's one (if ever).
# Check if we need to install everything or just check for changes in the package lock
# Note that creating the virtualenv with poetry makes the installation of blake3 fail
# for some reason, so I used some tricks to use venv instead.
- set -euo pipefail
- if poetry env info -p; then
echo "We have a cached venv";
else
echo "No cache, installing everything...";
apt-get update && apt-get install -y curl;
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh;
sh rustup.sh -v -y;
source $HOME/.cargo/env;
poetry env use "$(which python3)";
venvpath="$(poetry env info -p)";
rm -rf "$venvpath";
python3 -m venv "$venvpath";
fi;
- time poetry install --no-ansi
cache:
key:
prefix: "pypy"
files:
- poetry.lock
allow_failure: true
poetry cache pypy3.8:
extends: .poetry cache pypy
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8pypy"
cache:
key:
prefix: "pypy38"
files:
- poetry.lock
poetry cache pypy3.9:
extends: .poetry cache pypy
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.9pypy"
cache:
key:
prefix: "pypy39"
files:
- poetry.lock
poetry cache pypy3.10:
extends: .poetry cache pypy
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.10pypy"
cache:
key:
prefix: "pypy310"
files:
- poetry.lock
poetry cache stackless3.8:
extends: .poetry cache
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8stackless"
cache:
key:
prefix: "stackless38"
files:
- poetry.lock
allow_failure: true
python lint:
stage: static_analysis
needs:
- poetry cache py3.10
script:
- time poetry run inv reformat
- changes="$(git status --porcelain=v2 2>/dev/null)"
- if [ -n "$changes" ]; then printf "Code is not properly formatted\n%s" "$changes"; exit 1; fi
- time poetry run inv lint
cache:
key:
prefix: "py310"
files:
- poetry.lock
policy: pull
paths:
- .cache/poetry/
except:
- main
- tags
packages security:
stage: static_analysis
needs:
- poetry cache py3.10
script:
- time poetry run inv safety
cache:
key:
prefix: "py310"
files:
- poetry.lock
policy: pull
paths:
- .cache/poetry/
except:
- main
- tags
.tests:
stage: test
script:
- time poetry run inv tests --report
- poetry run coverage report --show-missing --fail-under 100
- poetry run coverage xml
cache:
key: "python-${CI_COMMIT_REF_SLUG}"
policy: pull
paths:
- .cache/poetry/
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
reports:
junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
except:
- main
- tags
tests py3.8:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8"
needs:
- poetry cache py3.8
- python lint
- packages security
cache:
key:
prefix: "py38"
files:
- poetry.lock
tests py3.9:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.9"
needs:
- poetry cache py3.9
- python lint
- packages security
cache:
key:
prefix: "py39"
files:
- poetry.lock
tests py3.10:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.10"
needs:
- poetry cache py3.10
- python lint
- packages security
cache:
key:
prefix: "py310"
files:
- poetry.lock
tests py3.11:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.11"
needs:
- poetry cache py3.11
- python lint
- packages security
cache:
key:
prefix: "py311"
files:
- poetry.lock
tests py3.12:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.12"
needs:
- poetry cache py3.12
- python lint
- packages security
cache:
key:
prefix: "py312"
files:
- poetry.lock
tests py3.13-pre:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.13-pre"
needs:
- poetry cache py3.13-pre
- python lint
- packages security
cache:
key:
prefix: "py313pre"
files:
- poetry.lock
allow_failure: true
tests pypy3.8:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8pypy"
needs:
- poetry cache pypy3.8
- python lint
- packages security
cache:
key:
prefix: "pypy38"
files:
- poetry.lock
allow_failure: true
tests pypy3.9:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.9pypy"
needs:
- poetry cache pypy3.9
- python lint
- packages security
cache:
key:
prefix: "pypy39"
files:
- poetry.lock
allow_failure: true
tests pypy3.10:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.10pypy"
needs:
- poetry cache pypy3.10
- python lint
- packages security
cache:
key:
prefix: "pypy310"
files:
- poetry.lock
allow_failure: true
tests stackless3.8:
extends: .tests
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.8stackless"
needs:
- poetry cache stackless3.8
- python lint
- packages security
script:
- time poetry run inv tests --no-coverage # with coverage is segfaulting for some reason
cache:
key:
prefix: "stackless38"
files:
- poetry.lock
allow_failure: true
# https://aquasecurity.github.io/trivy/v0.18.0/integrations/gitlab-ci/
security scanning:
stage: security_analysis
image:
name: docker.io/aquasec/trivy:latest
entrypoint: [ "" ]
needs:
- packages security
script:
- trivy --version
# update vulnerabilities db
- time trivy --cache-dir .cache/trivy/ image --download-db-only --no-progress
# Builds report and puts it in the default workdir $CI_PROJECT_DIR, so `artifacts:` can take it from there
- time trivy --cache-dir .cache/trivy/ fs --exit-code 0 --no-progress --format template --template "@/contrib/gitlab.tpl" --output "$CI_PROJECT_DIR/gl-container-scanning-report.json" .
# Prints the full report
- time trivy --cache-dir .cache/trivy/ fs --exit-code 0 --no-progress .
# Fails on every vulnerability that can be fixed
- time trivy --cache-dir .cache/trivy/ fs --exit-code 1 --ignore-unfixed --no-progress .
cache:
key: "trivy-${CI_COMMIT_REF_SLUG}"
policy: pull-push
paths:
- .cache/trivy/
artifacts:
reports:
# Enables https://docs.gitlab.com/ee/user/application_security/container_scanning/
# (the container scanning report is available on GitLab EE Ultimate or GitLab.com Gold)
container_scanning: gl-container-scanning-report.json
except:
variables:
- $CONTAINER_SCANNING_DISABLED
refs:
- tags
- main
.fuzz:
stage: security_analysis
image: "registry.gitlab.com/nevrona/public/poetry-docker:1.7.1-3.12"
needs:
- poetry cache py3.12
before_script:
- poetry add --group dev --source pythonfuzz pythonfuzz
cache:
- key:
prefix: "py312"
files:
- poetry.lock
policy: pull
paths:
- .cache/poetry/
- key: "fuzz-0"
policy: pull-push
paths:
- .fuzzed/
only:
- /^release\/.+$/
fuzz blake2signer:
extends: .fuzz
script:
- time poetry run inv fuzz --short --signer blake2signer
fuzz blake2timestampsigner:
extends: .fuzz
script:
- time poetry run inv fuzz --short --signer blake2timestampsigner
fuzz blake2serializersigner:
extends: .fuzz
script:
- time poetry run inv fuzz --short --signer blake2serializersigner
.publish:
stage: publish
before_script:
- echo "Artifacts from this job are temporary, and its sole purpose is to verify everything was published successfully without malicious intermediaries. Do not link nor depend on these artifacts! Fetch the package from PyPi or as specified in the README or docs."
after_script:
- apt-get update
- apt-get -y install --no-install-recommends b3sum
- sha256sum dist/*
- sha512sum dist/*
- b2sum dist/*
- b2sum -l 256 dist/*
- b3sum dist/*
artifacts:
paths:
- dist/
expire_in: 1 week
publish test:
extends: .publish
script:
- set -euo pipefail
- MAX_TRIES=${PUBLISH_TEST_MAX_TRIES:-10}
- poetry config repositories.testpypi https://test.pypi.org/legacy/
- poetry config pypi-token.testpypi "${POETRY_PYPI_TOKEN_TESTPYPI:?env var unset (forgot to protect branch?)}"
- count=0; while [ $count -lt $MAX_TRIES ]; do printf "Attempt %d of %d\n" "$((count + 1))" "$MAX_TRIES"; sleep "$((count / 2))"; poetry version prerelease && poetry publish --build -r testpypi && break || let "count+=1"; done
- if [ $count -ge $MAX_TRIES ]; then exit 1; fi
only:
- /^release\/.+$/
publish:
extends: .publish
script:
- set -euo pipefail
- poetry config pypi-token.pypi "${POETRY_PYPI_TOKEN_PYPI:?env var unset (forgot to protect branch?)}"
- poetry publish --build
only:
- tags