-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci-core.yml
583 lines (538 loc) · 16.7 KB
/
.gitlab-ci-core.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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# Copyright 2011-2024 The OTP authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# This file contains gitlab ci jobs running in all repositories.
# The jobs shouldn't have dependencies to jobs running not in all repositories
image: registry.gitlab.com/one-touch-pipeline/otp/otp-ci-java-17:2024-04-09
# notes:
## recursive expansion of variables does not work
## having multiple commands in one variable does not work
## putting the expire time to a variable does not work
variables:
GRADLE_OPTS: '-Xms1g -Xmx4g -Dorg.gradle.daemon=false'
GRAILS_OPTS: '-Xmx4g'
ARTIFACTS_BASE_DIRECTORY: 'artifacts'
GRADLE_USER_HOME: $CI_PROJECT_DIR/cache/gradle # overrides GRADLE_USER_HOME default for caching
NPM_CACHE: $CI_PROJECT_DIR/cache/npm
CYPRESS_CACHE: $CI_PROJECT_DIR/cache/cypress
GRADLE_WRAPPER_CACHE: $GRADLE_USER_HOME/wrapper
GRADLE_CACHES_CACHE: $GRADLE_USER_HOME/caches
GRADLE_BUILD_CACHE: $CI_PROJECT_DIR/cache/gradle-build-cache
BUILD_DIR: 'build'
ARTIFACT_DOWNLOAD_ATTEMPTS: "3"
GET_SOURCES_ATTEMPTS: "3"
RESTORE_CACHE_ATTEMPTS: "3"
ENABLE_CYPRESS: "true" #indicate, if cypress should run or not
CACHE_COUNTER: "3" # a counter to change cache names
#----------------------------
# shared
#----------------------------
stages:
- build
- test
- war
- codestyle
- scanning
- doc
- public doc
- update merge request
- cleanup
- trigger deployment
.shared:
cache:
gradle-wrapper:
#cache of gradle itself
key:
prefix: gradle-wrapper-$CACHE_COUNTER
files:
- $CI_PROJECT_DIR/gradle/wrapper/gradle-wrapper.properties
paths:
- $GRADLE_WRAPPER_CACHE
policy: pull
gradle-cache:
#caches created by gradle
key:
prefix: gradle-cache-$CACHE_COUNTER-$CI_JOB_NAME
files:
- $CI_PROJECT_DIR/gradle/wrapper/gradle-wrapper.properties
- $CI_PROJECT_DIR/gradle.properties
paths:
- $GRADLE_CACHES_CACHE
gradle-pipeline-cache:
#cache of gradle build cache
key:
prefix: gradle-build-cache-$CACHE_COUNTER-$CI_COMMIT_REF_NAME
files:
- $CI_PROJECT_DIR/gradle/wrapper/gradle-wrapper.properties
paths:
- $GRADLE_BUILD_CACHE
policy: pull
npm:
#cache of npm libraries
key:
prefix: npm-$CACHE_COUNTER
files:
- $CI_PROJECT_DIR/package-lock.json
paths:
- node_modules/
- $NPM_CACHE
- $CYPRESS_CACHE
rules-default:
- if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
rules-test:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
#common paths, shared with cypress
- src/main/**/*
- grails-app/conf/**/*
- grails-app/controllers/**/*
- grails-app/domain/**/*
- grails-app/i18n/**/*
- grails-app/init/**/*
- grails-app/services/**/*
#test specific parts
- src/test/**/*
- src/integration-test/**/*
- src/test-helper/**/*
rules-push:
- if: $CI_PIPELINE_SOURCE == "push"
rules-only-branch:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
.abstract_base_template:
dependencies: [ ]
needs: [ ]
cache: [ ]
rules:
- !reference [ .shared, rules-push ]
artifacts: &artifacts_template
expire_in: 4 week
before_script:
- set -e
- devScripts/gitlab-ci/init.sh
.abstract_base_template_with_cache:
extends: .abstract_base_template
dependencies:
- build gradle
needs:
- build gradle
cache:
- !reference [ .shared, cache, gradle-wrapper ]
- !reference [ .shared, cache, gradle-pipeline-cache ]
- !reference [ .shared, cache, gradle-cache ]
.abstract_test_template:
extends: .abstract_base_template_with_cache
stage: test
rules:
- !reference [ .shared, rules-default ]
- !reference [ .shared, rules-test ]
artifacts:
<<: *artifacts_template
paths:
- build/test-results/*/*.xml
- build/reports/tests
- build/reports/jacoco
- build/jacoco
reports:
junit: build/test-results/*/*.xml
when: always
# ------------------------------------------------------
# jobs stage build
# ------------------------------------------------------
build gradle:
extends: .abstract_base_template
stage: build
cache:
- key: !reference [ .shared, cache, gradle-wrapper, key ]
paths: !reference [ .shared, cache, gradle-wrapper, paths ]
policy: pull-push
- key: !reference [ .shared, cache, gradle-pipeline-cache, key ]
paths: !reference [ .shared, cache, gradle-pipeline-cache, paths ]
policy: pull-push
- !reference [ .shared, cache, gradle-cache ]
script:
- set -e
# compile also all tests
- ./gradlew --build-cache classes testHelperClasses testClasses integrationTestClasses workflowTestClasses
# ------------------------------------------------------
# jobs stage scanning
# ------------------------------------------------------
license check:
image: groovy:3.0-jdk17-alpine
stage: scanning
dependencies: [ ]
needs: [ ]
cache: [ ]
rules:
- !reference [ .shared, rules-push ]
script:
- groovy devScripts/gitlab-ci/license-checker/licensecheck.groovy
# ------------------------------------------------------
# jobs stage tests
# ------------------------------------------------------
unit tests:
extends: .abstract_test_template
script:
- set -e
- ./gradlew --build-cache test
integration tests:
extends: .abstract_test_template
services:
- name: postgres:14.9-bullseye
alias: postgres
variables:
USE_POSTGRES: "DOCKER_CI"
POSTGRES_HOST_AUTH_METHOD: "trust"
script:
- set -e
- ./gradlew --build-cache integrationTest
test coverage:
extends: .abstract_base_template_with_cache
stage: test
needs:
- build gradle
- unit tests
- integration tests
dependencies:
- build gradle
- unit tests
- integration tests
coverage: '/Instruction Coverage: (\d+(?:\.\d+)?)%/'
script:
- set -e
- ./gradlew --build-cache classes
- ./gradlew --build-cache --exclude-task test --exclude-task integrationTest --rerun-tasks jacocoAllTestReport jacocoToCobertura
when: always
rules:
- !reference [ .shared, rules-default ]
- !reference [ .shared, rules-test ]
artifacts:
<<: *artifacts_template
paths:
- build/reports/jacoco/allTest
- build/reports/jacocoToCobertura
reports:
coverage_report:
coverage_format: cobertura
path: build/reports/jacocoToCobertura/*.xml
when: always
test migration:
extends: .abstract_base_template_with_cache
stage: test
services:
- postgres:14.9-bullseye
variables:
POSTGRES_DB: otp
POSTGRES_USER: otp
POSTGRES_PASSWORD: otp
before_script:
- set -e
- devScripts/gitlab-ci/init.sh
- cp $OTP_PROPERTIES_POSTGRES ~/.otp.properties
script:
- set -e
- ./gradlew --build-cache dbmUpdate
- bash ./devScripts/grails-migration-plugin/create-dbm-gorm-diff-without-false-changes.sh testing
- bash ./devScripts/grails-migration-plugin/check-for-changelog-file.sh testing
- bash ./devScripts/grails-migration-plugin/check-variable-problems.sh
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
#migration test specific
- grails-app/domain/**/*
- migrations/**/*
artifacts:
<<: *artifacts_template
paths:
- migrations/changelogs/*/testing.groovy
when: on_failure
cypress tests:
extends: .abstract_base_template_with_cache
stage: test
rules:
- if: $ENABLE_CYPRESS == "false"
when: never
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
#common paths, shared with unit/integration
- grails-app/conf/**/*
- grails-app/controllers/**/*
- grails-app/domain/**/*
- grails-app/i18n/**/*
- grails-app/init/**/*
- grails-app/services/**/*
- src/main/**/*
#test specific parts
- cypress/**/*
- cypress.config.js
- devScripts/gitlab-ci/cypress/**/*
- docker/**/*
- grails-app/assets/**/*
- grails-app/taglib/**/*
- grails-app/views/**/*
- migrations/**/*
- package.json
- package-lock.json
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
HOST_IP: "0.0.0.0"
GRADLE_OPTS: '-Xms1g -Xmx4g -Dorg.gradle.daemon=true'
services:
- name: docker:dind
alias: openssh-server
script:
- set -e
- devScripts/gitlab-ci/cypress/cypress.sh
artifacts:
<<: *artifacts_template
paths:
- cypress/screenshots
- cypressReport.txt
- logs/
when: always
cache:
- !reference [ .shared, cache, gradle-wrapper ]
- !reference [ .shared, cache, gradle-pipeline-cache ]
- !reference [ .shared, cache, gradle-cache ]
- !reference [ .shared, cache, npm ]
parallel:
matrix:
- SUITE:
- "overview"
- "project"
- "operatorAndAdminPages"
- "workflowSystem"
- "others"
# This job checks, that all cypress suites (directories in cypress/e2e/) are defined in the ci job 'cypress tests'
check cypress suite configured for ci:
dependencies: [ ]
needs: [ ]
stage: test
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
- .gitlab-ci-core.yml
- cypress/e2e/**/*
script:
- set -e
- devScripts/gitlab-ci/cypress/check-suite-configured-for-ci.sh
# ------------------------------------------------------
# jobs stage codestyle
# ------------------------------------------------------
codenarc:
extends: .abstract_base_template_with_cache
stage: codestyle
script:
- set -e
- ./gradlew --build-cache codenarcAll
after_script:
- set -e
- devScripts/gitlab-ci/codenarc-informations.sh
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
#codenarc test specific
- grails-app/**/*.groovy
- src/**/*
artifacts:
<<: *artifacts_template
paths:
- build/reports/codenarc
when: always
reports:
metrics: metrics.txt
eslint:
extends: .abstract_base_template
stage: codestyle
script:
- set -e
- ./gradlew --build-cache esLintExportCi
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
# ci specific
- grails-app/assets/javascripts/**/*
- package.json
- package-lock.json
artifacts:
<<: *artifacts_template
paths:
- build/reports/eslint
when: always
cache:
- !reference [ .shared, cache, gradle-wrapper ]
- !reference [ .shared, cache, gradle-cache ]
- !reference [ .shared, cache, npm ]
# ------------------------------------------------------
# jobs stage war
# ------------------------------------------------------
create war:
extends: .abstract_base_template_with_cache
stage: war
script:
- devScripts/gitlab-ci/createWar.sh
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
# ci specific
- grails-app/**/*
- src/main/**/*
# ------------------------------------------------------
# jobs stage doc
# ------------------------------------------------------
create doc:
extends: .abstract_base_template
stage: doc
script:
- set -e
- ./gradlew --build-cache generateHtml
rules:
- !reference [ .shared, rules-default ]
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/master'
paths:
#common paths, configs
- build.gradle
- devScripts/gitlab-ci/init.sh
- .gitlab-ci-core.yml
- gradle/**/*
- gradle.properties
- settings.gradle
# ci specific
- docs/**/*
artifacts:
<<: *artifacts_template
paths:
- build/docs
generate_changelog:
extends: .abstract_base_template
stage: doc
script:
- mkdir -p $ARTIFACTS_BASE_DIRECTORY
- set +e
- LATEST_TAG=$(git describe --abbrev=0 --tags --match "v*.*.*" HEAD^)
- set -e
- 'if [[ -z "${LATEST_TAG}" ]]; then git fetch --unshallow --tags ; LATEST_TAG=$(git describe --abbrev=0 --tags --match "v*.*.*" HEAD^) ; fi'
- echo $LATEST_TAG
- git config gitchangelog.rc-path scripts/gitchangelog/gitchangelog.rc.reference
- scripts/gitchangelog/gitchangelog.py ^$LATEST_TAG HEAD >> $ARTIFACTS_BASE_DIRECTORY/CHANGELOG.txt
- git config gitchangelog.rc-path scripts/gitchangelog/release_notes_gitchangelog.rc.reference
- scripts/gitchangelog/gitchangelog.py ^$LATEST_TAG HEAD >> $ARTIFACTS_BASE_DIRECTORY/RELEASE_NOTES.txt
- cat $ARTIFACTS_BASE_DIRECTORY/CHANGELOG.txt
- cat $ARTIFACTS_BASE_DIRECTORY/RELEASE_NOTES.txt
artifacts:
<<: *artifacts_template
paths:
- $ARTIFACTS_BASE_DIRECTORY
when: on_success
# ------------------------------------------------------
# jobs stage public doc
# ------------------------------------------------------
# This must only run on the master branch to deploy the only pages site
# https://docs.gitlab.com/ee/user/project/pages/introduction.html#gitlab-ciyml-for-a-repository-where-theres-also-actual-code
pages:
stage: public doc
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
dependencies:
- create doc
script:
- mv build/docs public
artifacts:
expire_in: 1 day
paths:
- public
variables:
GIT_STRATEGY: none
# ------------------------------------------------------
# jobs stage cleanup
# ------------------------------------------------------
prune stale branches:
stage: cleanup
variables:
GIT_DEPTH: "0"
needs: [ ]
rules:
- if: $CI_COMMIT_TAG
script:
- devScripts/gitlab-ci/clearStaleBranches.sh