-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
154 lines (139 loc) · 4.8 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
stages:
- cache
- tests
- quality-assurance
- quality-assurance-report
.job-base-template: &job-base-defintion
image: jakzal/phpqa:php8.1
.vendor-install-template: &vendor-install-defintion
before_script:
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- ln -f -s .env.test .env
# re-install vendors to prevent from ci cache failure
- composer --version && composer install -vv --prefer-dist --no-interaction --optimize-autoloader --no-scripts || echo "Composer install fail"
.cache-pull-template: &cache-pull-defintion
cache:
key: "$CI_PROJECT_PATH-php"
paths:
- vendor
policy: pull
create_cache:
image: jakzal/phpqa:php8.1-alpine
script:
- composer --version && composer install -vv --prefer-dist --no-interaction --optimize-autoloader --no-scripts || echo "Composer install fail"
cache:
key: "$CI_PROJECT_PATH-php"
paths:
- vendor
stage: cache
except:
- master
unit_tests:
<<: *job-base-defintion
<<: *vendor-install-defintion
<<: *cache-pull-defintion
script:
- pecl install xdebug
- echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini
- php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --colors=never --coverage-html var/artefacts/coverage/
coverage: /^\s+Lines:\s+(\d+)\.\d+%/
artifacts:
paths:
- var/artefacts/coverage/
expire_in: 1 month
stage: tests
except:
- master
check-coverage:
image: alpine:latest
stage: quality-assurance
variables:
JOB_NAME: unit_tests
TARGET_BRANCH: develop
before_script:
- apk add --update --no-cache curl jq
rules:
- if: '$CI_COMMIT_BRANCH != $TARGET_BRANCH'
script:
- TARGET_PIPELINE_ID=`curl -s "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines?ref=${TARGET_BRANCH}&status=success" | jq ".[0].id"`
- TARGET_COVERAGE=`curl -s "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${TARGET_PIPELINE_ID}/jobs" | jq --arg JOB_NAME "$JOB_NAME" '.[] | select(.name==$JOB_NAME) | .coverage'`
- CURRENT_COVERAGE=`curl -s "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs" | jq --arg JOB_NAME "$JOB_NAME" '.[] | select(.name==$JOB_NAME) | .coverage'`
- if [ "$CURRENT_COVERAGE" -lt "$TARGET_COVERAGE" ]; then echo "Coverage decreased from ${TARGET_COVERAGE} to ${CURRENT_COVERAGE}" && exit 1; fi;
# TODO validate doctrine migrations and schema
check-security:
<<: *job-base-defintion
<<: *vendor-install-defintion
<<: *cache-pull-defintion
script:
- local-php-security-checker
stage: quality-assurance
except:
- master
phpstan:
<<: *job-base-defintion
<<: *vendor-install-defintion
<<: *cache-pull-defintion
script:
- phpstan analyse -c phpstan.neon -l2 src
stage: quality-assurance
except:
- master
lint:
<<: *job-base-defintion
<<: *vendor-install-defintion
<<: *cache-pull-defintion
script:
- cp -f .env.dist .env
- bin/console lint:twig templates
- bin/console lint:yaml config
- bin/console lint:yaml src
- bin/console lint:yaml fixtures
stage: quality-assurance
except:
- master
phpmd:
<<: *job-base-defintion
script:
- phpmd src/ html .phpmd.xml --reportfile var/artefacts/phpmd/index.html --ignore-violations-on-exit
artifacts:
paths:
- var/artefacts/phpmd
expire_in: 1 month
stage: quality-assurance
only:
- develop
php-cs-fixer:
<<: *job-base-defintion
script:
- php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run --using-cache=no --verbose --diff --stop-on-violation
stage: quality-assurance
except:
- master
phpmetrics:
<<: *job-base-defintion
script:
- phpmetrics --report-html=var/artefacts/phpmetrics --exclude=migrations .
artifacts:
paths:
- var/artefacts/phpmetrics
expire_in: 1 month
stage: quality-assurance
only:
- develop
pages:
<<: *job-base-defintion
script:
- export
- rm -rf public/*
- cp .gitlab-pages.html var/artefacts/index.html
- sed -i "s|PLACEHOLDER_PROJECT_PATH|${CI_PROJECT_PATH}|g" var/artefacts/index.html
- sed -i "s|PLACEHOLDER_PROJECT_NAME|${CI_PROJECT_NAME}|g" var/artefacts/index.html
- sed -i "s|PLACEHOLDER_GIT_COMMIT_SHA|${CI_COMMIT_SHA}|g" var/artefacts/index.html
- mv var/artefacts/* public/
artifacts:
paths:
- public
expire_in: 1 month
stage: quality-assurance-report
only:
- develop