-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
394 lines (342 loc) · 9.42 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
default:
image: python:3.9
cache:
- key:
files:
- ${CI_PROJECT_DIR}/poetry.lock
paths:
- ${CI_PROJECT_DIR}/.venv
- key: "${CI_PROJECT_ID}"
paths:
- ${CI_PROJECT_DIR}/.cache/pip
- key: "${CI_JOB_ID}"
paths:
- ${CI_PROJECT_DIR}/**/__pycache__/
stages:
- 🎨 format 🎨
- 🦄 quality 🦄
- 🔒️ security 🔒️
- 🤞 test 🤞
- 🚀 release 🚀
workflow:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH
variables:
FF_USE_FASTZIP: "true"
# These can be specified per job or per pipeline
ARTIFACT_COMPRESSION_LEVEL: "fast"
CACHE_COMPRESSION_LEVEL: "fast"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
VENV: "$CI_PROJECT_DIR/.venv"
ACTIVATE_VENV: "$VENV/bin/activate"
PYTHONPATH: "."
GIT_STRATEGY: "fetch"
GIT_SUBMODULE_STRATEGY: "recursive"
ASDF_PYTHON_VERSION: "3.9"
LM_PYTHON_VERSION: "3.9"
SAFETY_POLICY_FILE: "$CI_PROJECT_DIR/.safety-policy.yml"
SAFETY_COLOR: "True"
CI_SERVER_URL: "https://etulab.univ-amu.fr"
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
- template: Jobs/Secret-Detection.latest.gitlab-ci.yml
# Define good stage for includes
dependency_scanning:
cache: [ ]
stage: 🔒️ security 🔒️
interruptible: true
.secret-analyzer:
cache: [ ]
stage: 🔒️ security 🔒️
interruptible: true
# Install dependencies
🔧 build env 🔧:
cache:
- key:
files:
- poetry.lock
paths:
- ${CI_PROJECT_DIR}/.venv
policy: pull-push
- key: "${CI_PROJECT_ID}"
paths:
- ${CI_PROJECT_DIR}/.cache/pip
policy: pull-push
stage: .pre
interruptible: true
before_script:
- python --version
- pip install --upgrade pip
- export PATH="$PATH":"$HOME/.local/bin"
- pip install --user pipx
- pipx ensurepath
- pipx install virtualenv
- pipx install poetry
- poetry --version
script:
- virtualenv $VENV
- source $ACTIVATE_VENV
- pip install --upgrade pip
- poetry install
- poetry update
artifacts:
paths:
- $VENV
# Pre script
.load_env:
interruptible: true
cache:
- key:
files:
- poetry.lock
paths:
- ${CI_PROJECT_DIR}/.venv
policy: pull
- key: "${CI_PROJECT_ID}"
paths:
- ${CI_PROJECT_DIR}/.cache/pip
policy: pull
needs:
- 🔧 build env 🔧
before_script:
- source $ACTIVATE_VENV
# Format code
.common_format:
extends: .load_env
stage:
🎨 format 🎨
🩹 isort 🎨:
extends: .common_format
script:
- isort src --check
🩹 black 🎨:
extends: .common_format
script:
- black src --check
🩹 yamllint 🎨:
extends: .common_format
rules:
- changes:
- $CI_PROJECT_DIR/**/*.yml
- $CI_PROJECT_DIR/**/*.yaml
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
script:
- yamllint src tests
🩹 markdownlint 🎨:
cache: [ ]
image: node:slim
rules:
- changes:
- $CI_PROJECT_DIR/**/*.md
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
stage:
🎨 format 🎨
before_script:
- node --version
- npm install markdownlint
- npm install markdownlint-cli
script:
- ./node_modules/markdownlint-cli/markdownlint.js src tests -j -o markdownlint.json -c .markdownlint.yaml
artifacts:
paths:
- markdownlint.json
# Security check
.common_security:
extends: .load_env
stage: 🔒️ security 🔒️
.common_security_after_format:
extends: .common_security
needs:
- !reference [ .common_security, needs ]
- 🩹 black 🎨
- 🩹 isort 🎨
🔍️ bandit 🔒️ 1/2:
extends: .common_security_after_format
script:
- bandit -r src -f xml -o bandit.xml
artifacts:
reports:
junit: bandit.xml
🔍️ bandit 🔒️ 2/2:
extends: .common_security_after_format
script:
- bandit -r src -f html -o bandit.html
artifacts:
paths:
- bandit.html
🔍️ mypy 🏷️:
extends: .common_security_after_format
cache:
key: "mypy-${$CI_COMMIT_BRANCH}"
paths:
- ${CI_PROJECT_DIR}/.mypy_cache
policy: pull-push
script:
- mypy src --install-types --non-interactive --html-report html_mypy --junit-xml mypy.xml
artifacts:
reports:
junit: mypy.xml
paths:
- html_mypy
🔍️ safety 🔒️:
extends: .common_security
# Ignore CVS 51457, the project uses GIT not SVN
script:
- safety check -i 51457 -o html --save-html safety.html -o json --save-json safety.json
artifacts:
paths:
- safety.json
- safety.html
🔍️ dodgy 🔐:
extends: .common_security
script:
- dodgy src
# Quality tests
.common_quality:
extends: .load_env
stage: 🦄 quality 🦄
needs:
- !reference [ .load_env, needs ]
- 🩹 black 🎨
- 🩹 isort 🎨
🔍️ pycodestyle 🎨:
extends: .common_quality
script:
- pycodestyle src
🔍️ pydocstyle 📝:
extends: .common_quality
script:
- pydocstyle src
🔍️ pylint 🧐:
extends: .common_quality
script:
- pylint src --output-format json --output pylint.json
artifacts:
reports:
codequality: pylint.json
🔍️ ruff 🧐:
extends: .common_quality
cache:
key: "ruff-${$CI_COMMIT_BRANCH}"
paths:
- ${CI_PROJECT_DIR}/.ruff_cache
policy: pull-push
script:
- ruff src --format gitlab > ruff.json
artifacts:
reports:
codequality: ruff.json
🔍️ vulture ⚰️:
extends: .common_quality
script:
- vulture src
🔍️ interrogate 📝:
extends: .common_quality
script:
- interrogate src --generate-badge .
artifacts:
paths:
- interrogate_badge.svg
🔍️ deptry ⚰️:
extends: .load_env
stage: 🦄 quality 🦄
script:
- deptry src -o deptry.json
artifacts:
paths:
- deptry.json
# Tests
.common_test:
extends: .load_env
stage: 🤞 test 🤞
cache:
key: "pytest-${$CI_COMMIT_BRANCH}"
paths:
- ${CI_PROJECT_DIR}/.pytest_cache
policy: pull-push
before_script:
- !reference [ .load_env, before_script ]
- export PYTHONPATH="./src"
🤞 unittests 🤞:
extends: .common_test
needs:
- !reference [ .common_test, needs ]
- 🔍️ bandit 🔒️ 1/2
- 🔍️ bandit 🔒️ 2/2
- 🔍️ pycodestyle 🎨
- 🔍️ pydocstyle 📝
- 🔍️ pylint 🧐
- 🔍️ ruff 🧐
- 🔍️ mypy 🏷️
- 🔍️ vulture ⚰️
- 🔍️ safety 🔒️
- 🔍️ dodgy 🔐
- 🔍️ interrogate 📝
- 🔍️ deptry ⚰️
script:
- pytest
🤞 coverage 🔍️:
extends: .common_test
needs:
- !reference [ .common_test, needs ]
- 🤞 unittests 🤞
coverage: /TOTAL\s+[\d\.]+\s+[\d\.]+\s+[\d\.]+\s+[\d\.]+\s+([\d\.]+)/
script:
- pytest --cov=src --cov=tests --junit-xml=coverage.xml --cov-report=html:coverage_html
- coverage report
allow_failure: true
artifacts:
when: always
paths:
- coverage.xml
- coverage_html
reports:
junit: coverage.xml
# Build the package
.common_release:
stage: 🚀 release 🚀
rules:
# Run this job when a tag is created manually
- if: $CI_COMMIT_TAG
🔧 publish package 🚧:
extends:
- .load_env
- .common_release
needs:
- !reference [ .load_env, needs ]
- 🤞 coverage 🔍️
before_script:
- export PATH="$PATH":"$HOME/.local/bin"
- pip install --user pipx
- pipx ensurepath
- pipx install poetry
script:
- poetry config repositories.gitlab $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/pypi
- poetry build
- poetry publish -r gitlab --username=ci_cd --password=$PUBLISHER_PASSWORD
artifacts:
when: on_success
paths:
- dist
🔖 release version 🚧:
cache: []
extends: .common_release
needs:
- 🔧 publish package 🚧
image: registry.gitlab.com/gitlab-org/release-cli:latest
script:
- echo "Release created"
release:
tag_name: $CI_COMMIT_TAG
name: 'Release ${CI_COMMIT_TAG}'
description: 'Release created using the release-cli.'
assets:
links:
- name: '${CI_PROJECT_NAME} PyPi package'
url: '${CI_SERVER_URL}/${CI_PROJECT_PATH}/-/packages'