-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
499 lines (455 loc) · 16 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
include:
- local: '/.gitlab-ci/stage-functional-tests-local-git.yml'
- template: Code-Quality.gitlab-ci.yml
image: xorti/tiki-devops:php-7.4-qa
variables:
MYSQL_ROOT_PASSWORD: secret
COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/.composercache"
COMPOSER_FLAGS: '--ansi --no-progress --prefer-dist -n'
SVN_SCHEDULER_NAME: 'test-tiki-manager-svn'
SRC_SCHEDULER_NAME: 'test-tiki-manager-src'
INSTANCE_TYPE_SSH: 'ssh'
INSTANCE_TYPE_FTP: 'ftp'
stages:
- build
- quality
- unit-tests
- pre-functional-tests
- functional-tests
- package
- prepare
- release
- vendors_update
.composer-cache:
cache: &composer-cache
key: cache-tiki-manager
paths:
- vendor/
- vendor-bin/
- .composercache/files
artifacts:
paths:
- vendor/
- vendor-bin/
when: on_success
expire_in: 1h
.install-composer-script: &install-composer-script
- composer install $COMPOSER_FLAGS
- composer bin all install $COMPOSER_FLAGS
.update-composer-script: &update-composer-script
- composer update $COMPOSER_FLAGS
.git-config: &git-config
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global --add safe.directory "*"
composer:
stage: build
script:
*install-composer-script
cache:
<<: *composer-cache
#
# Lint
#
.lint-scripts: &lint-scripts
stage: quality
script:
- git log -m --first-parent -1 --name-only --diff-filter=d --pretty="format:" | grep -v "^$" | sort -u | grep '\.php$' - 2>&1 > /dev/null || { git log -m -1 --name-only && echo && echo 'No files to be processed. Skipping...' && echo && exit 0; }
- git log -m -1 --name-only
- git log -m --first-parent -1 --name-only --diff-filter=d --pretty="format:" | grep -v "^$" | sort -u | xargs -L 1 php -l
needs: [ ]
allow_failure: false
lint-scripts-php74:
image: xorti/tiki-devops:php-7.4-qa
<<: *lint-scripts
lint-scripts-php80:
image: xorti/tiki-devops:php-8.0-qa
<<: *lint-scripts
lint-scripts-php81:
image: xorti/tiki-devops:php-8.1-qa
<<: *lint-scripts
phpcs:
stage: quality
script:
- *install-composer-script
- xargs php vendor/squizlabs/php_codesniffer/bin/phpcs -s --runtime-set ignore_warnings_on_exit true
needs:
- composer
cache:
<<: *composer-cache
policy: pull
code_quality:
stage: quality
artifacts:
reports:
codequality: gl-code-quality-report.json
#----------------------------------------------------------------------------------------------------------------------#
# UNIT TESTS SECTION
#----------------------------------------------------------------------------------------------------------------------#
.unit-tests: &unit-tests
stage: unit-tests
services:
- name: mysql:5.6
alias: mysql
script:
- XDEBUG_MODE=coverage ./vendor/bin/simple-phpunit tests/ --group unit --coverage-text --colors=never --log-junit report.xml
needs:
- composer
cache:
<<: *composer-cache
policy: pull
allow_failure: false
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
artifacts:
when: always
reports:
junit: report.xml
.unit-tests-composer-install: &unit-tests-composer-install
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- *install-composer-script
- composer build-phar
<<: *unit-tests
.unit-tests-composer-update: &unit-tests-composer-update
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- *update-composer-script
- *install-composer-script
- composer build-phar
<<: *unit-tests
unit-tests-php74:
image: xorti/tiki-devops:php-7.4-qa
<<: *unit-tests-composer-install
unit-tests-php80:
image: xorti/tiki-devops:php-8.0-qa
<<: *unit-tests-composer-update
unit-tests-php81:
image: xorti/tiki-devops:php-8.1-qa
<<: *unit-tests-composer-update
#----------------------------------------------------------------------------------------------------------------------#
# FUNCTIONAL TESTS SECTION
#----------------------------------------------------------------------------------------------------------------------#
.tiki-manager-cache:
cache: &tiki-manager-cache
key: cache-tiki-$VCS
paths:
- cache/
- vendor/
- vendor-bin/
- ${COMPOSER_CACHE_DIR}/files
.cache-warmup-tiki:
image: xorti/tiki-devops:php-7.4-qa
stage: pre-functional-tests
before_script:
- source .env.gitlab-ci
- *update-composer-script
- *install-composer-script
cache:
<<: *tiki-manager-cache
needs:
- composer
dependencies:
- composer
cache-warmup-tiki-git:
extends: .cache-warmup-tiki
variables:
VCS: git
script:
- *git-config
- TIKI_CACHE=cache/tiki-git-$PREV_VERSION_BRANCH
- |
if [ ! -d "$TIKI_CACHE" ]; then
git clone --depth 1 -b $PREV_VERSION_BRANCH $GIT_TIKIWIKI_URI $TIKI_CACHE;
else
git -C $TIKI_CACHE pull
fi;
- composer install -d $TIKI_CACHE/vendor_bundled $COMPOSER_FLAGS --no-dev
except:
refs:
- schedules
variables:
- $SCHEDULER == $SVN_SCHEDULER_NAME
- $SCHEDULER == $SRC_SCHEDULER_NAME
cache-warmup-tiki-svn:
extends: .cache-warmup-tiki
variables:
VCS: svn
script:
- TIKI_CACHE=cache/tiki-svn-branches_$PREV_VERSION_BRANCH
- |
if [ ! -d "$TIKI_CACHE" ]; then
svn checkout $SVN_TIKIWIKI_URI/branches/$PREV_VERSION_BRANCH $TIKI_CACHE
else
cd $TIKI_CACHE && svn up
fi;
- composer install -d $TIKI_CACHE/vendor_bundled $COMPOSER_FLAGS --no-dev
only:
refs:
- schedules
variables:
- $SCHEDULER == $SVN_SCHEDULER_NAME
download-tiki-src-files:
extends: .cache-warmup-tiki
script:
- |
SRC_PATH='data/tiki_src/' &&\
if [ ! -f "${SRC_PATH}tiki-${LATEST_SRC_RELEASE}.tar.gz" ]; then wget -nv --directory-prefix=${SRC_PATH} ${URL_LATEST_SRC_RELEASE}; fi; \
if [ ! -f "${SRC_PATH}tiki-${PREV_SRC_MINOR_RELEASE}.tar.gz" ]; then wget -nv --directory-prefix=${SRC_PATH} ${URL_PREV_SRC_MINOR_RELEASE}; fi; \
if [ ! -f "${SRC_PATH}tiki-${PREV_SRC_MAJOR_RELEASE}.tar.gz" ]; then wget -nv --directory-prefix=${SRC_PATH} ${URL_PREV_SRC_MAJOR_RELEASE}; fi;
cache:
paths:
- data/tiki_src/
- cache/
- vendor/
- vendor-bin/
- .composercache/files
artifacts:
name: tiki-src
paths:
- data/tiki_src/
when: on_success
only:
refs:
- schedules
variables:
- $SCHEDULER == $SRC_SCHEDULER_NAME
#----------------------------------------------------------------------------------------------------------------------#
# FUNCTIONAL TESTS SECTION
#----------------------------------------------------------------------------------------------------------------------#
.setup-env: &setup-env
- VCS=${VCS:-$DEFAULT_PHP_VERSION}
- echo APP_ENV=gitlab-ci >> .env
- echo DEFAULT_VCS=$VCS >> .env
- cat .env
.setup-keys: &setup-keys
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
.template-tiki-manager-commands: &template-tiki-manager-commands
image: xorti/tiki-devops:php-all-qa
stage: functional-tests
services:
- name: mysql:5.6
alias: mysql
before_script:
- *setup-env
- *setup-keys
- source .env.gitlab-ci
# Use PHP_VERSION variable to use a different version
- PHP_VERSION=${PHP_VERSION:-$DEFAULT_PHP_VERSION}
- rm /etc/alternatives/php && ln -s /usr/bin/php${PHP_VERSION} /etc/alternatives/php
- php -v
- *update-composer-script
- *install-composer-script
script:
- ./vendor/bin/simple-phpunit tests/Command/$TEST_FILE
cache:
<<: *tiki-manager-cache
policy: pull
allow_failure: false
.template-tiki-manager-commands-git: &template-tiki-manager-commands-git
<<: *template-tiki-manager-commands
variables:
VCS: git
dependencies:
- cache-warmup-tiki-git
needs:
- cache-warmup-tiki-git
before_script:
- !reference [ .template-tiki-manager-commands, before_script ]
- *git-config
except:
variables:
- $SCHEDULER == $SVN_SCHEDULER_NAME
- $SCHEDULER == $SRC_SCHEDULER_NAME
.template-tiki-manager-commands-svn: &template-tiki-manager-commands-svn
<<: *template-tiki-manager-commands
dependencies:
- cache-warmup-tiki-svn
needs:
- cache-warmup-tiki-svn
only:
refs:
- schedules
variables:
- $SCHEDULER == $SVN_SCHEDULER_NAME
.template-tiki-manager-commands-src: &template-tiki-manager-commands-src
<<: *template-tiki-manager-commands
dependencies:
- download-tiki-src-files
needs:
- download-tiki-src-files
only:
refs:
- schedules
variables:
- $SCHEDULER == $SRC_SCHEDULER_NAME
#----------------------------------------------------------------------------------------------------------------------#
# PACKAGE SECTION
#----------------------------------------------------------------------------------------------------------------------#
phar:
stage: package
script:
- composer install $COMPOSER_FLAGS
- composer build-phar
allow_failure: false
needs:
- composer
cache:
<<: *composer-cache
artifacts:
name: tiki-manager.phar
paths:
- build/tiki-manager.phar
when: on_success
only:
refs:
- master
- tags
compressed:
stage: package
variables:
PACK_FILES_FOLDERS_LIST: config data scripts src vendor hooks .env.dist composer.json composer.lock LICENSE README.md tiki-manager tiki-manager.php VERSION .version
script:
- composer install --no-dev $COMPOSER_FLAGS
- git log --pretty=fuller 'HEAD^..HEAD' > VERSION
- git log --pretty="format:TIKI_MANAGER_GIT_DATE=%cd%nTIKI_MANAGER_GIT_HASH=%h" 'HEAD^..HEAD' --date="format:%Y%m%d%H%M%S" > .version
- find ${PACK_FILES_FOLDERS_LIST} -type f -exec chmod 664 {} \;
- find ${PACK_FILES_FOLDERS_LIST} -type d -exec chmod 775 {} \;
- chmod 775 tiki-manager
- tar czvf tiki-manager.tgz ${PACK_FILES_FOLDERS_LIST}
allow_failure: false
needs:
- composer
cache:
<<: *composer-cache
artifacts:
name: tiki-manager.tgz
paths:
- tiki-manager.tgz
when: on_success
only:
refs:
- master
- tags
except:
variables:
- $SCHEDULER == "update_vendor"
#----------------------------------------------------------------------------------------------------------------------#
# PREPARE SECTION
#----------------------------------------------------------------------------------------------------------------------#
upload:
stage: prepare
image: curlimages/curl:latest
allow_failure: false
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ # Run this job when a tag is created, and tag match version regexp
needs:
- compressed
- phar
script:
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file build/tiki-manager.phar "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/tiki-manager/${CI_COMMIT_TAG}/tiki-manager.phar"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file tiki-manager.tgz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/tiki-manager/${CI_COMMIT_TAG}/tiki-manager.tgz"
prepare_changelog:
stage: prepare
allow_failure: false
needs:
- composer
cache:
<<: *composer-cache
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ # Run this job when a tag is created, and tag match version regexp
script:
# Generating a changelog. Here is how it works:
# * it assumes we are running with a tag on the current commit (thats the case in release_job, thanks to the rules section)
# * `git describe --tags --abbrev=0 --match="v*" HEAD^1` <= search the last tag (matching v*) starting at the previous commit, and return the tag name
# * `git [...] log`: get all commit subjects from the tag computed by git-describe to HEAD
# * we filter to remove subject that does not start with something like [FIX]
# * then we produce a changelog file, by reordering commit by types (first important types, then less important ones)
# * we create a release_notes.txt file with the release changelog content.
# Note: if the commit as multiple types ([SEC][FIX] for example), only the first one will be taken into account for the ordering.
# Note: this will not work for the very first tag.
- echo "Generating changelog"
- git --no-pager log --pretty=format:"%s" $(git describe --tags --abbrev=0 --match="v*" HEAD^1)..HEAD | grep -E '^\[[A-Z]+\]' > changelog.tmp;
- echo "tiki-manager $CI_COMMIT_TAG" > release_notes.txt;
- echo "" >> release_notes.txt;
- grep -E '^\[MOD\]' changelog.tmp | uniq >> release_notes.txt || true;
- grep -E '^\[REM\]' changelog.tmp | uniq >> release_notes.txt || true;
- grep -E '^\[SEC\]' changelog.tmp | uniq >> release_notes.txt || true;
- grep -E '^\[NEW\]' changelog.tmp | uniq >> release_notes.txt || true;
- grep -v -E '^\[(MOD|REM|SEC|NEW)\]' changelog.tmp | sort -u >> release_notes.txt || true;
- rm changelog.tmp;
# and we make a list from all commit subjects:
- sed -i -e 's/^\[/* [/g' release_notes.txt
- cat release_notes.txt;
artifacts:
name: release_notes.txt
paths:
- release_notes.txt
when: on_success
#----------------------------------------------------------------------------------------------------------------------#
# RELEASE SECTION
#----------------------------------------------------------------------------------------------------------------------#
release_job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ # Run this job when a tag is created, and tag match version regexp
dependencies:
- upload
- prepare_changelog
needs:
- upload
- prepare_changelog
script:
- echo "Running release_job"
release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
tag_name: '$CI_COMMIT_TAG'
description: release_notes.txt
assets:
links:
- name: tiki-manager.phar
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/tiki-manager/${CI_COMMIT_TAG}/tiki-manager.phar"
link_type: 'package'
filepath: '/tiki-manager.phar'
- name: tiki-manager.tgz
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/tiki-manager/${CI_COMMIT_TAG}/tiki-manager.tgz"
link_type: 'package'
filepath: '/tiki-manager.tgz'
#----------------------------------------------------------------------------------------------------------------------#
# MAINTENANCE SECTION
#----------------------------------------------------------------------------------------------------------------------#
update_vendor_dependencies:
stage: vendors_update
dependencies:
- composer
needs:
- composer
variables:
BRANCH_NAME: "${CI_COMMIT_REF_NAME}_vendor_update"
COMMIT_MESSAGE: "[UPD] Update ${CI_COMMIT_REF_NAME} vendor dependencies"
CI_REPOSITORY_URL: "https://${GITLAB_USER_LOGIN}:${GITLAB_USER_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git"
COMPOSER_DISCARD_CHANGES: "true"
COMPOSER_NO_INTERACTION: "1"
before_script:
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
script:
- composer -V | grep "version 2" || composer self-update --2
- DATE=`date +%Y%m%d`
- BRANCH_NAME="${BRANCH_NAME}_${DATE}"
- php scripts/manager/update_vendor.php
- if git diff --quiet --exit-code composer.lock; then exit 0; fi;
- if git rev-parse --verify ${BRANCH_NAME}; then git branch -D ${BRANCH_NAME}; fi;
- git checkout -b ${BRANCH_NAME}
- git add composer.lock
- git commit -m "${COMMIT_MESSAGE}"
- git push ${CI_REPOSITORY_URL} HEAD:${BRANCH_NAME} --quiet
- |
HOST=${CI_PROJECT_URL} CI_PROJECT_ID=${CI_PROJECT_ID} SOURCE_BRANCH=${BRANCH_NAME} TARGET_BRANCH=${CI_COMMIT_REF_NAME} GITLAB_USER_ID=${GITLAB_USER_ID} PRIVATE_TOKEN=${GITLAB_USER_TOKEN} TARGET_PROJECT_ID=${TARGET_PROJECT_ID} SET_MERGE=${SET_MERGE} \
/bin/bash .gitlab-ci/auto_merge_request.sh "${COMMIT_MESSAGE} (${DATE})"
only:
variables:
- $SCHEDULER == "update_vendor"