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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_REF_PROTECTED == "true"'
image: studip/studip:tests-php8.1
variables:
FF_NETWORK_PER_BUILD: 1
GIT_DEPTH: 1
MYSQL_RANDOM_ROOT_PASSWORD: "true"
MYSQL_DATABASE: studip_db
MYSQL_USER: studip_user
MYSQL_PASSWORD: studip_password
MYSQL_HOST: mariadb
DEMO_DATA: "true"
MAIL_TRANSPORT: debug
PHPSTAN_LEVEL: 0
# Optimize caching
FF_USE_FASTZIP: "true"
CACHE_COMPRESSION_LEVEL: "fast"
# Use faster docker driver
DOCKER_DRIVER: overlay2
# Images
NODE_IMAGE: node:18
# Directories
CACHE_DIR: .caches
REPORT_DIR: .reports
# Set npm cache directory
npm_config_cache: $CI_PROJECT_DIR/.npm
stages:
- noop
- build
- checks
- analyse
- test
- cache
- packaging
- release
.scripts:
mkdir-caches:
- mkdir -p $CACHE_DIR
mkdir-reports:
- mkdir -p $REPORT_DIR
install-composer:
- make composer-dev
configure-studip:
- !reference [.scripts, install-composer]
- cp docker/studip/config_local.php config/config_local.inc.php
- cp config/config.inc.php.dist config/config.inc.php
initialize-studip-database:
- !reference [.scripts, configure-studip]
- chmod +x .gitlab/scripts/install_db.sh
- .gitlab/scripts/install_db.sh
- cli/studip migrate
.caches:
composer: &composer-cache
key:
files:
- composer.lock
fallback_keys:
- composer-default
paths:
- composer/
policy: pull-push
npm: &npm-cache
key:
files:
- package-lock.json
fallback_keys:
- npm-default
paths:
- .npm
policy: pull-push
.definitions:
mariadb-service: &mariadb-service
- name: mariadb:10.2.7
command: [ "--sql_mode=","--character-set-client=utf8","--character-set-server=utf8","--collation-server=utf8_unicode_ci"]
mysql-service: &mysql-service
- name: mysql:8.0
command: [ "--sql_mode=","--character-set-server=utf8mb4","--collation-server=utf8mb4_general_ci"]
php-changed: &php-changed
- changes:
paths:
- "**/*.php"
- composer.lock
compare_to: 'refs/heads/main'
css-changed: &css-changed
- changes:
paths:
- "resources/assets/stylesheets/**/*"
- package-lock.json
compare_to: 'refs/heads/main'
js-changed: &js-changed
- changes:
paths:
- "resources/assets/javascripts/**/*"
- "resources/vue/**/*"
- package-lock.json
compare_to: 'refs/heads/main'
noop:
stage: noop
script:
- echo "No relevant changes detected - skipping the rest of the pipeline."
rules:
- changes:
paths:
- '**/*.php'
- composer.lock
- 'resources/vue/**/*'
- 'resources/assets/**/*'
- package-lock.json
when: never
- when: always
build-composer:
stage: build
needs: []
rules: *php-changed
interruptible: true
variables:
COMPOSER_CACHE: $CACHE_DIR/composer-cache
before_script:
- mkdir -p $COMPOSER_CACHE
script:
- composer install
cache:
- <<: *composer-cache
lint-php:
stage: checks
needs: [build-composer]
rules: *php-changed
variables:
CACHE_LOCATION: $CACHE_DIR/phplint-cache
PHPLINT_JSON_REPORT: $REPORT_DIR/phplint-report.json
PHPLINT_CODE_QUALITY_REPORT: $REPORT_DIR/phplint-codequality.json
interruptible: true
cache:
- <<: *composer-cache
- key: "$CI_JOB_NAME_SLUG"
paths:
- $CACHE_LOCATION
before_script:
- !reference [.scripts, mkdir-caches]
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, install-composer]
- source .gitlab/scripts/ci-helpers.sh
script:
- COMPOSER_MEMORY_LIMIT=-1
composer exec phplint
--
$(get_changed_files '*.php')
--output=$PHPLINT_JSON_REPORT
--format=json
--cache=$CACHE_LOCATION
after_script:
- ./.gitlab/scripts/convert-phplint-report $PHPLINT_JSON_REPORT > $PHPLINT_CODE_QUALITY_REPORT
artifacts:
reports:
codequality: $PHPLINT_CODE_QUALITY_REPORT
lint-php-8.3:
image: studip/studip:tests-php8.3
stage: checks
needs: [build-composer]
rules: *php-changed
variables:
CACHE_LOCATION: $CACHE_DIR/phplint-cache
PHPLINT_JSON_REPORT: $REPORT_DIR/phplint-report-8.3.json
PHPLINT_CODE_QUALITY_REPORT: $REPORT_DIR/phplint-codequality-8.3.json
interruptible: true
cache:
- <<: *composer-cache
- key: "$CI_JOB_NAME_SLUG"
paths:
- $CACHE_LOCATION
before_script:
- !reference [.scripts, mkdir-caches]
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, install-composer]
- source .gitlab/scripts/ci-helpers.sh
script:
- COMPOSER_MEMORY_LIMIT=-1
composer exec phplint
--
$(get_changed_files '*.php')
--output=$PHPLINT_JSON_REPORT
--format=json
--cache=$CACHE_LOCATION
after_script:
- ./.gitlab/scripts/convert-phplint-report $PHPLINT_JSON_REPORT > $PHPLINT_CODE_QUALITY_REPORT
artifacts:
reports:
codequality: $PHPLINT_CODE_QUALITY_REPORT
lint-js:
stage: checks
needs: []
rules: *js-changed
image: $NODE_IMAGE
variables:
CACHE_LOCATION: $CACHE_DIR/eslint-cache
ESLINT_CODE_QUALITY_REPORT: $REPORT_DIR/eslint-codequality.json
cache:
- <<: *npm-cache
- key: "$CI_JOB_NAME_SLUG"
paths:
- $CACHE_LOCATION
policy: pull-push
interruptible: true
before_script:
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, mkdir-caches]
- npm ci --prefer-offline
- source .gitlab/scripts/ci-helpers.sh
script:
- npx eslint
$(get_changed_files '*.js' '*.ts' '*.vue')
--config eslint.config.mjs
--cache --cache-location $CACHE_LOCATION
--format gitlab
artifacts:
reports:
codequality: $ESLINT_CODE_QUALITY_REPORT
lint-css:
stage: checks
needs: []
rules: *css-changed
image: $NODE_IMAGE
variables:
CACHE_LOCATION: $CACHE_DIR/stylelint-cache
STYLELINT_CODE_QUALITY_REPORT: $REPORT_DIR/stylelint-codequality.json
interruptible: true
cache:
- <<: *npm-cache
- key: "$CI_JOB_NAME_SLUG"
paths:
- $CACHE_LOCATION
policy: pull-push
before_script:
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, mkdir-caches]
- npm ci --prefer-offline
- source .gitlab/scripts/ci-helpers.sh
script:
- npx stylelint
$(get_changed_files '*.scss' '*.css')
--cache --cache-location $CACHE_LOCATION
--custom-formatter=node_modules/stylelint-formatter-gitlab
--output-file $STYLELINT_CODE_QUALITY_REPORT
artifacts:
reports:
codequality: $STYLELINT_CODE_QUALITY_REPORT
phpstan:
stage: analyse
needs: [build-composer]
rules: *php-changed
variables:
CACHE_LOCATION: $CACHE_DIR/phpstan
PHPSTAN_CODE_QUALITY_REPORT: $REPORT_DIR/phpstan-codequality.json
interruptible: true
cache:
- <<: *composer-cache
- key: "$CI_JOB_NAME_SLUG"
paths:
- $CACHE_LOCATION
before_script:
- !reference [.scripts, mkdir-caches]
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, install-composer]
- source .gitlab/scripts/ci-helpers.sh
- |
cat <<EOF > phpstan.neon
includes:
- phpstan.neon.dist
parameters:
tmpDir: $CACHE_LOCATION
EOF
script:
- RELEVANT=$(get_changed_files '*.php' | grep -vE '^lib/ilias_interface/studip_referrer_.*\.php$' || true)
- |
if [ -z "$RELEVANT" ]; then
echo "No relevant files changed - skipping PHPStan"
exit 0
fi
composer/bin/phpstan analyse $RELEVANT --memory-limit=1G --no-progress --level=$PHPSTAN_LEVEL --error-format=gitlab > $PHPSTAN_CODE_QUALITY_REPORT
after_script:
- rm phpstan.neon
artifacts:
reports:
codequality: $PHPSTAN_CODE_QUALITY_REPORT
test-unit:
stage: test
needs: [lint-php]
rules: *php-changed
variables:
PHPUNIT_XML_REPORT: $REPORT_DIR/phpunit-report.xml
cache:
<<: *composer-cache
policy: pull
allow_failure: false
interruptible: true
before_script:
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, configure-studip]
script:
- 'composer/bin/codecept
run unit
--xml=$PHPUNIT_XML_REPORT
-o "paths: output: ."'
after_script:
- sed -i "s%$PWD/%%" $PHPUNIT_XML_REPORT
artifacts:
reports:
junit: $PHPUNIT_XML_REPORT
test-jest:
stage: test
needs: [lint-js]
rules: *js-changed
image: $NODE_IMAGE
variables:
JS_TEST_REPORT: $REPORT_DIR/jest.xml
cache:
- <<: *npm-cache
interruptible: true
before_script:
- !reference [.scripts, mkdir-reports]
- npm install
script:
- JEST_JUNIT_OUTPUT_FILE="$JS_TEST_REPORT" npx jest tests/jest/ --ci --reporters=default --reporters=jest-junit
artifacts:
reports:
junit: $JS_TEST_REPORT
test-functional:
stage: test
needs: [lint-php]
rules: *php-changed
variables:
FUNCTIONAL_XML_REPORT: $REPORT_DIR/functional-report.xml
FUNCTIONAL_CODE_QUALITY_REPORT: $REPORT_DIR/functional-codequality.json
MYSQL_HOST: mysql
cache:
<<: *composer-cache
policy: pull
services:
- !reference [.definitions, mysql-service]
allow_failure: false
interruptible: true
before_script:
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, initialize-studip-database]
script:
- 'composer/bin/codecept
run functional
--xml=$FUNCTIONAL_XML_REPORT
-o "paths: output: ."'
after_script:
- sed -i "s%$PWD/%%" $FUNCTIONAL_XML_REPORT
artifacts:
reports:
junit: $FUNCTIONAL_XML_REPORT
test-jsonapi:
stage: test
needs: [lint-php]
rules: *php-changed
cache:
<<: *composer-cache
policy: pull
services:
- !reference [.definitions, mariadb-service]
variables:
JSONAPI_XML_REPORT: $REPORT_DIR/jsonapi-report.xml
interruptible: true
before_script:
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, initialize-studip-database]
script:
- 'composer/bin/codecept
run jsonapi
--xml=$JSONAPI_XML_REPORT
-o "paths: output: ."'
after_script:
- sed -i "s%$PWD/%%" $JSONAPI_XML_REPORT
artifacts:
reports:
junit: $JSONAPI_XML_REPORT
test-assets:
stage: test
needs: []
rules:
- !reference [.definitions, js-changed]
- !reference [.definitions, css-changed]
image: $NODE_IMAGE
cache:
- <<: *npm-cache
interruptible: true
before_script:
- npm install
script:
- npm run webpack-dev
test-e2e:
stage: test
# needs: [lint-css, lint-js, lint-php]
image: mcr.microsoft.com/playwright:v1.33.0-jammy
services:
- name: mariadb
command: ["--sql_mode="]
variables:
PHP_WEBSERVER_URL: localhost:65432
E2E_REPORT: $REPORT_DIR/e2e.xml
interruptible: true
when: manual
cache:
- !reference [.caches, composer]
- !reference [.caches, npm]
before_script:
- mkdir ./bin
- apt-get update
- apt -y install software-properties-common
- add-apt-repository ppa:ondrej/php
- apt-get update
- DEBIAN_FRONTEND=noninteractive
apt-get -yq install
make zip unzip mariadb-client
php7.4 libapache2-mod-php7.4 php7.4-common php7.4-curl php7.4-mbstring
php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-xml php7.4-intl php7.4-ldap
php7.4-imagick php7.4-json php7.4-cli
- echo "short_open_tag=On" >> /etc/php/7.4/php.ini
- echo "short_open_tag=On" >> /etc/php/7.4/cli/php.ini
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=./bin --filename=composer
- export PATH="./bin:$PATH"
- php -r "unlink('composer-setup.php');"
- !reference [.scripts, mkdir-reports]
- !reference [.scripts, initialize-studip-database]
- ./cli/studip config:set SHOW_TERMS_ON_FIRST_LOGIN 0
- npm install playwright
- npm ci
- npx playwright install --with-deps
script:
- php -S $PHP_WEBSERVER_URL -t public -q &
- PHP_SERVER_PID=$!
- PLAYWRIGHT_JUNIT_OUTPUT_NAME="$E2E_REPORT"
PLAYWRIGHT_BASE_URL="http://$PHP_WEBSERVER_URL"
npx playwright test --reporter=junit --grep-invert a11y
- kill -3 $PHP_SERVER_PID
artifacts:
reports:
junit: $E2E_REPORT
packaging:
stage: packaging
cache: []
rules:
- if: $CI_COMMIT_TAG
before_script:
- echo GE_JOB_ID=$CI_JOB_ID >> .packaging.env
- mkdir .pkg
script:
- echo 'Running packaging job'
- make build clean-npm
- zip -r9 .pkg/studip-$CI_COMMIT_TAG.zip *
- tar -czf .pkg/studip-$CI_COMMIT_TAG.tar.gz *
artifacts:
name: 'Stud.IP-Release-$CI_COMMIT_TAG'
paths:
- .pkg/studip-$CI_COMMIT_TAG.zip
- .pkg/studip-$CI_COMMIT_TAG.tar.gz
reports:
dotenv: .packaging.env
expire_in: never
build_image:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stage: build
when: manual
interruptible: true
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
script:
- /kaniko/executor --context=dir://${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/docker/studip/Dockerfile --destination ${IMAGE_TAG} --cache=true
release:
stage: release
image: studip/release-cli
cache: []
rules:
- if: $CI_COMMIT_TAG
script:
- echo 'Running release job'
needs:
- job: packaging
artifacts: true
release:
name: "$CI_COMMIT_TAG"
description: "https://gitlab.studip.de/studip/studip/-/blob/${CI_COMMIT_TAG}/ChangeLog.md"
tag_name: "$CI_COMMIT_TAG"
assets:
links:
- name: "studip-$CI_COMMIT_TAG.zip"
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-$CI_COMMIT_TAG.zip"
link_type: package
- name: "studip-$CI_COMMIT_TAG.tar.gz"
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-$CI_COMMIT_TAG.tar.gz"
link_type: package
|