-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
509 lines (477 loc) · 16.5 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
stages:
- test
- doc
- build
- build_check
- notif
- schedule
- schedule-test
before_script:
- export COVERAGE_FILE=coverage-$CI_NODE_INDEX-$CI_PIPELINE_ID
- echo 'sudo --preserve-env=PYTHONPATH,CI_NODE_TOTAL,CI_NODE_INDEX,COVERAGE_FILE -u www-data python3-coverage run -a --source se,sosse ./sosse/sosse_admin.py "$@"' > /tmp/sudo_sosse
- chmod 755 /tmp/sudo_sosse
- test -z "$APT_PROXY" || (echo "Acquire::http::Proxy \"$APT_PROXY\";" > /etc/apt/apt.conf.d/proxy.conf)
variables:
GIT_SUBMODULE_STRATEGY: recursive
unit_tests:
image: biolds/sosse:debian-test
parallel: 3
artifacts:
when: always
paths:
- se/migrations/*.py
- log/*
- coverage-*
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
script:
- export PYTHONPATH="$CI_PROJECT_DIR"
- make _docker_unit_test_prepare
- failed=0
- /tmp/sudo_sosse test -v3 --failfast || failed=1
- /tmp/sudo_sosse load_se tests/opensearch.xml || failed=1
- /tmp/sudo_sosse update_se || failed=1
- /tmp/sudo_sosse shell -c 'from django.contrib.auth.models import User; User.objects.all().delete()' || failed=1
- /tmp/sudo_sosse default_admin || failed=1
- /tmp/sudo_sosse generate_secret || failed=1
- /tmp/sudo_sosse extract_doc cli > /dev/null || failed=1
- /tmp/sudo_sosse extract_doc conf > /dev/null || failed=1
- /tmp/sudo_sosse extract_doc se > /dev/null || failed=1
- python3 ./sosse/sosse_admin.py makemigrations || failed=1
- /tmp/sudo_sosse migrate || failed=1
- /tmp/sudo_sosse migrate se 0001 || failed=1
- mv /var/log/sosse log
- exit $failed
coverage_report:
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
image: biolds/sosse:debian-test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- unit_tests
artifacts:
when: always
paths:
- htmlcov/*
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
script:
- export COVERAGE_FILE=coverage
- python3-coverage combine --data-file=coverage coverage-*
- python3-coverage report --omit "*/se/deps/*,*/dist-packages/*"
- python3-coverage html --omit "*/se/deps/*,*/dist-packages/*"
- python3-coverage xml --omit "*/se/deps/*,*/dist-packages/*"
.functional_tests: &functional_tests
image: biolds/sosse:pip-test
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- doc_code_extract
artifacts:
when: always
paths:
- tests/robotframework/screenshots/*
- tests/robotframework/*.html
- log/*
script:
- make _pip_functional_tests
- (make _rf_functional_$TEST_SUITE ; echo -n $? > /tmp/ret_code) || true
- mv /var/log/sosse log
- test "$(cat /tmp/ret_code)" -eq 0
functional_tests_chromium:
<<: *functional_tests
variables:
TEST_SUITE: tests
BROWSER: chromium
functional_tests_firefox:
<<: *functional_tests
variables:
TEST_SUITE: tests
BROWSER: firefox
functional_guides_chromium:
<<: *functional_tests
variables:
TEST_SUITE: guides
BROWSER: chromium
migrations:
image: biolds/sosse:debian-test
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
script:
- apt update
- 'grep ^Depends: debian/control | sed -e "s/.*},//" -e "s/,//g" | xargs apt install -y'
- /etc/init.d/postgresql start
- export PYTHONPATH="$CI_PROJECT_DIR"
- chown www-data:www-data -R /var/log/sosse
- /tmp/sudo_sosse default_conf | sed -e "s/^#db_pass=.*/db_pass=sosse/" -e "s/^#debug=.*/debug=true/" > /etc/sosse/sosse.conf
- MIGRATION_COUNT="$(ls se/migrations/*.py|grep '/[0-9]'|wc -l)"
- python3 ./sosse/sosse_admin.py makemigrations
- MIGRATION_COUNT2="$(ls se/migrations/*.py|grep '/[0-9]'|wc -l)"
- test "$MIGRATION_COUNT" -eq "$MIGRATION_COUNT2"
static_checks:
image: biolds/sosse:debian-test
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
script:
- make static_checks
pre_commit:
image: biolds/sosse:debian-test
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
script:
- /pre-commit-venv/bin/pre-commit autoupdate
- git diff --exit-code
- /pre-commit-venv/bin/pre-commit run -a
doc_gen:
image: biolds/sosse:debian-test
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
artifacts:
paths:
- doc/source/*_generated.rst
- doc/source/*/*_generated.rst
- doc/source/CHANGELOG.md
- doc/source/introduction.md
script:
- make doc_gen
doc_code_extract:
image: biolds/sosse:doc
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- doc_gen
artifacts:
paths:
- doc/code_blocks.json
script:
- sed -e 's/|[^|]*| //g' -e 's/^.. \(image\|figure\)::.*//' -i $(find doc -name \*.rst)
- make _build_doc
doc:
image: biolds/sosse:doc
stage: doc
rules:
- if: $CI_PIPELINE_SOURCE == "push"
artifacts:
paths:
- doc/build/*
needs:
# if any artifact is need to bild the doc, then its build step must also be added to the `jobs_name` in doc/get_artifacts.py
- doc_gen
- functional_tests_chromium
#- functional_tests_firefox -> commented because only the artifacts (screenshot) from Chromium are needed
- functional_guides_chromium
script:
- make _build_doc
- test -n "$RTD_TOKEN" && curl -X POST -d "branches=main" -d "token=$RTD_TOKEN" -d "default_branch=main" https://readthedocs.org/api/v2/webhook/sosse/236935/ || true
pip_pkg:
image: biolds/sosse:pip-test
rules:
- if: $CI_PIPELINE_SOURCE == "push"
artifacts:
paths:
- dist/*
stage: build
needs:
- doc
- migrations
- unit_tests
- functional_tests_chromium
- functional_tests_firefox
- static_checks
script:
- sed -e "s/^SOSSE_VERSION_TAG = .*/SOSSE_VERSION_TAG = '${CI_COMMIT_TAG/v/}'/" -i sosse/settings.py
- sed -e "s/^SOSSE_VERSION_COMMIT = .*/SOSSE_VERSION_COMMIT = '${CI_COMMIT_SHORT_SHA}'/" -i sosse/settings.py
- make _pip_pkg
debian_pkg:
image: biolds/sosse:debian-pkg
#image: registry.gitlab.com/biolds1/sosse/debian-pkg:latest
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- doc
- migrations
- unit_tests
- functional_tests_chromium
- functional_tests_firefox
- static_checks
artifacts:
paths:
- deb/*.deb
script:
- cd "$CI_PROJECT_DIR"
- rm -rf htmlcov
- sed -e "s/^SOSSE_VERSION_TAG = .*/SOSSE_VERSION_TAG = '${CI_COMMIT_TAG/v/}'/" -i sosse/settings.py
- sed -e "s/^SOSSE_VERSION_COMMIT = .*/SOSSE_VERSION_COMMIT = '${CI_COMMIT_SHORT_SHA}'/" -i sosse/settings.py
- mkdir /deb
- make _deb
- mv /deb .
changelog:
image: biolds/sosse:debian-test
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs: []
artifacts:
paths:
- CHANGELOG.md
variables:
GIT_DEPTH: 0 # disable shallow cloning since the step requires all tags
script:
- 'last_ver="$(git tag -l | sort -V | tail -n 1 | sed -e "s/^v//")"'
- 'new_ver="${last_ver%.*}.$((${last_ver/*./} + 1))"'
- echo "$last_ver / $new_ver"
- 'curl -X GET -H "PRIVATE-TOKEN: $GITLAB_REST_API_CHANGELOG" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/repository/changelog?version=$new_ver" | jq -r .notes | tee /tmp/new'
- cat /tmp/new CHANGELOG.md > new.md && mv new.md CHANGELOG.md
doc_test_debian:
image: debian:bookworm
stage: build_check
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- doc_code_extract
script:
- apt update
- apt install -y make jq
- make _doc_test_debian
doc_test_pip:
image: debian:bookworm
stage: build_check
rules:
- if: $CI_PIPELINE_SOURCE == "push"
needs:
- doc_code_extract
script:
- apt update
- apt install -y make jq
- make _doc_test_pip
.debian_pkg_check: &debian_pkg_check
image: biolds/sosse:debian-base
stage: build_check
rules:
- if: $CI_PIPELINE_SOURCE == "push"
artifacts:
when: always
paths:
- tests/robotframework/screenshots/*
- tests/robotframework/*.html
- log/*
needs:
- doc_code_extract
- debian_pkg
script:
- apt update
- apt install -y jq make virtualenv
- make _deb_pkg_functional_tests
- (make _rf_functional_tests ; echo -n $? > /tmp/ret_code) || true
- mv /var/log/sosse log
- test "$(cat /tmp/ret_code)" -eq 0
debian_pkg_check_chromium:
<<: *debian_pkg_check
variables:
TEST_SUITE: tests
BROWSER: chromium
debian_pkg_check_firefox:
<<: *debian_pkg_check
variables:
TEST_SUITE: tests
BROWSER: firefox
.pip_pkg_check: &pip_pkg_check
image: biolds/sosse:pip-test
stage: build_check
rules:
- if: $CI_PIPELINE_SOURCE == "push"
artifacts:
when: always
paths:
- tests/robotframework/screenshots/*
- tests/robotframework/*.html
- log/*
needs:
- doc_code_extract
- pip_pkg
script:
- make _pip_pkg_functional_tests
- (make _rf_functional_tests ; echo -n $? > /tmp/ret_code) || true
- mv /var/log/sosse log
- test "$(cat /tmp/ret_code)" -eq 0
pip_pkg_check_chromium:
<<: *pip_pkg_check
variables:
TEST_SUITE: tests
BROWSER: chromium
pip_pkg_check_firefox:
<<: *pip_pkg_check
variables:
TEST_SUITE: tests
BROWSER: firefox
discord_tag_notif:
image: debian:bookworm
stage: notif
allow_failure: true
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
needs:
- doc_gen
- pip_pkg
- debian_pkg_check_chromium
- debian_pkg_check_firefox
script: |
test -n "$DISCORD_TAG_NOTIF_URL"
apt update
apt install -y jq curl make
changelog="$(grep -v '^# Changelog' < doc/source/CHANGELOG.md | sed '/^$/Q' | sed -e 's#(\(https\?://[^)]*\))#(<\1\>)#g')"
msg="$(jq -n --arg tag "$CI_COMMIT_TAG" --arg changelog "$changelog" '{"content": ($tag + " was just released! 🎉\n\n" + $changelog)}')"
curl -X POST -H 'Content-Type: application/json' -d "$msg" "$DISCORD_TAG_NOTIF_URL"
rebuild_upgrade_check:
image: biolds/sosse:latest
stage: schedule
needs: []
artifacts:
when: always
paths:
- pkg_status/*
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
- if: $CI_PIPELINE_SOURCE == "push"
script:
- test "$CI_PIPELINE_SOURCE" != push || exit 0
- apt update
- mkdir pkg_status
- apt list --upgradable | tee pkg_status/apt_list_upgradable
- /venv/bin/pip install -r requirements.txt --upgrade --dry-run | tee pkg_status/pip_upgrade
rebuild_docker:
image: biolds/sosse:docker
stage: schedule
tags:
- docker-socket
needs:
- job: rebuild_upgrade_check
artifacts: true
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
- if: $CI_PIPELINE_SOURCE == "push"
script:
- test "$CI_PIPELINE_SOURCE" = push || test -e pkg_status/apt_list_upgradable
- test "$CI_PIPELINE_SOURCE" = push || test -e pkg_status/pip_upgrade
- mkdir -p ~/.docker
- 'echo "{\"auths\":{\"registry.gitlab.com\":{\"auth\":\"$GITLAB_DOCKER_REGISTRY_KEY\"}}}" > ~/.docker/config.json'
- "if (cat pkg_status/apt_list_upgradable | grep -v ^Listing | grep -q .) || (grep -q ^Would pkg_status/pip_upgrade) ; then NO_BUILD=0 ; else NO_BUILD=1 ; fi"
- "test $NO_BUILD -eq 0 || docker pull debian:bookworm"
- "test $NO_BUILD -eq 0 || docker tag debian:bookworm registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
- "test $NO_BUILD -eq 0 || docker push registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
- "test $NO_BUILD -eq 0 || exit 0"
- "docker rmi biolds/sosse:pip-base ||:"
- "docker rmi biolds/sosse:pip-release ||:"
- test "$CI_PIPELINE_SOURCE" != schedule || make docker_release_build
- test "$CI_PIPELINE_SOURCE" != push || make docker_release_build_test
- "docker tag biolds/sosse:pip-release registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
- "docker push registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
rebuild_unit_tests:
image: "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
needs:
- job: rebuild_docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
- if: $CI_PIPELINE_SOURCE == "push"
stage: schedule-test
script:
- "test -d /venv || exit 0" # No upgrade was built, we exit without error
- "/etc/init.d/postgresql start ||:"
- "until pg_isready; do sleep 1; done"
- apt-get update
- apt-get install -y rsync git
- sed -e 's#python3#/venv/bin/python3#' -i ./tests/test_app.sh
- ./tests/test_app.sh
- bash -c "$(grep -E '(mkdir|touch|chown|test)' /run.sh)" # Create log dir and files
- /venv/bin/sosse-admin default_conf | sed -e "s/^#db_pass=.*/db_pass=sosse/" -e "s/^#debug=.*/debug=true/" -e "s/#dl_check_time=.*/dl_check_time=1/" -e "s,#online_check_url.*,online_check_url=http://localhost:8000/," -e "s/^#chromium_options=\(.*\)/chromium_options=\1 --no-sandbox --disable-dev-shm-usage/" > /etc/sosse/sosse.conf
- cat /etc/sosse/sosse.conf
- su - postgres -c "psql --command 'ALTER USER sosse WITH SUPERUSER;'"
- sudo -E -u www-data /venv/bin/python3 -m sosse.sosse_admin test -v3
rebuild_functional_tests_firefox:
image: "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
needs:
- job: rebuild_docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
- if: $CI_PIPELINE_SOURCE == "push"
stage: schedule-test
artifacts:
when: always
paths:
- tests/robotframework/screenshots/*
- tests/robotframework/*.html
- log/*
script:
- "test -d /venv || exit 0" # No upgrade was built, we exit without error
- /run.sh &
- apt-get update
- apt-get install -y rsync git curl
- sed -e 's#python3#/venv/bin/python3#' -i ./tests/test_app.sh
- ./tests/test_app.sh
- echo -e "#!/bin/bash\nexec /venv/bin/python3 -m sosse.sosse_admin \"\$@\"" > sosse-admin.sh
- chmod 755 sosse-admin.sh
- 'echo "SOSSE_ADMIN: $PWD/sosse-admin.sh" > tests/robotframework/config.yaml'
- until curl --silent --fail http://127.0.0.1/ > /dev/null; do sleep 1; done
- mkdir -p /var/lib/sosse/screenshots && git clone --depth=1 https://github.com/GurvanKervern/dummy-static-website /var/lib/sosse/screenshots/website
- make _rf_functional_tests
rebuild_functional_tests_chromium:
image: "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
needs:
- job: rebuild_docker
stage: schedule-test
artifacts:
when: always
paths:
- tests/robotframework/screenshots/*
- tests/robotframework/*.html
- log/*
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
- if: $CI_PIPELINE_SOURCE == "push"
script:
- "test -d /venv || exit 0" # No upgrade was built, we exit without error
- /run.sh &
- apt-get update
- apt-get install -y rsync git curl
- sed -e 's#python3#/venv/bin/python3#' -i ./tests/test_app.sh
- ./tests/test_app.sh
- echo -e "#!/bin/bash\nexec /venv/bin/python3 -m sosse.sosse_admin \"\$@\"" > sosse-admin.sh
- chmod 755 sosse-admin.sh
- 'echo "SOSSE_ADMIN: $PWD/sosse-admin.sh" > tests/robotframework/config.yaml'
- until curl --silent --fail http://127.0.0.1/ > /dev/null; do sleep 1; done
- mkdir -p /var/lib/sosse/screenshots && git clone --depth=1 https://github.com/GurvanKervern/dummy-static-website /var/lib/sosse/screenshots/website
- make _rf_functional_tests
rebuild_docker_push:
image: biolds/sosse:docker
tags:
- docker-socket
needs:
- job: rebuild_unit_tests
- job: rebuild_functional_tests_firefox
- job: rebuild_functional_tests_chromium
- job: rebuild_upgrade_check
artifacts: true
stage: schedule-test
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "stable"
script:
- "if (cat pkg_status/apt_list_upgradable | grep -v ^Listing | grep -q .) || (grep -q ^Would pkg_status/pip_upgrade) ; then NO_BUILD=0 ; else NO_BUILD=1 ; fi"
- "test $NO_BUILD -eq 0 || exit 0"
- mkdir ~/.docker/
- 'echo "{\"auths\":{\"registry.gitlab.com\":{\"auth\":\"$GITLAB_DOCKER_REGISTRY_KEY\"}}}" > ~/.docker/config.json'
- docker pull "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID"
- docker tag "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID" biolds/sosse:latest
- docker tag "registry.gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_PIPELINE_ID" biolds/sosse:stable
- 'echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"$DOCKER_KEY\"}}}" > ~/.docker/config.json'
- docker push biolds/sosse:latest
- docker push biolds/sosse:stable