-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
345 lines (318 loc) · 9.69 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
345 lines (318 loc) · 9.69 KB
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
stages:
- build
- scheduled tasks
- code quality
- dependency scanning
- outdated packages
- test
- deploy
workflow:
auto_cancel:
on_new_commit: interruptible
# Cache default configuration
cache: &global_cache
key: "$CI_PIPELINE_ID"
paths:
- node_modules
- public/build
- var/sass
- vendor
policy: pull
# Build section
Install dependencies and build assets:
image: sumocoders/cli-tools-php85:latest
script:
- COMPOSER_MEMORY_LIMIT=-1 composer install --no-scripts --no-progress
- COMPOSER_MEMORY_LIMIT=-1 composer run-script post-autoload-dump
- php bin/console importmap:install --no-interaction
- php bin/console sass:build --no-interaction
cache:
<<: *global_cache
policy: pull-push
stage: build
interruptible: true
tags:
- docker
# Code Quality section
Mago - check code styling:
image:
name: ghcr.io/carthage-software/mago:1
entrypoint: [ '' ]
script:
- mago --config=./mago.dist.toml --colors=always fmt --check
after_script:
- >
if [ "$CI_JOB_STATUS" != 'success' ]; then
mago --config=./mago.dist.toml --colors=always fmt --dry-run
fi
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
Mago - lint:
image:
name: ghcr.io/carthage-software/mago:1
entrypoint: [ '' ]
script:
- mago --config=./mago.dist.toml --colors=always lint --reporting-format=rich --minimum-fail-level=warning
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
Mago - analyse:
image:
name: ghcr.io/carthage-software/mago:1
entrypoint: [ '' ]
script:
- mago --config=./mago.dist.toml --colors=always analyse --reporting-format=rich --minimum-fail-level=warning
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
Mago - guard:
image:
name: ghcr.io/carthage-software/mago:1
entrypoint: [ '' ]
script:
- mago --config=./mago.dist.toml --colors=always guard --reporting-format=rich --minimum-fail-level=warning
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
PHP_CodeSniffer - check code styling:
image: sumocoders/cli-tools-php85:latest
script:
- php vendor/bin/phpcs --colors --report-full -s --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=phpcs-report.json
artifacts:
expire_in: 1 week
reports:
codequality: phpcs-report.json
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
PHPStan - check for bugs:
image: sumocoders/cli-tools-php85:latest
before_script:
- php bin/console cache:warmup --env=dev
script:
- php vendor/bin/phpstan analyse --memory-limit=-1 --error-format=gitlab --no-progress --no-interaction > phpstan-report.json
after_script:
# Run it again so the output is visible in the job
- >
if [ "$CI_JOB_STATUS" != 'success' ]; then
php vendor/bin/phpstan analyse --memory-limit=-1 --no-progress
fi
artifacts:
expire_in: 1 week
reports:
codequality: phpstan-report.json
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
Twig-CS-Fixer - check code styling:
image: sumocoders/cli-tools-php85:latest
script:
- php vendor/bin/twig-cs-fixer lint templates/ --report=junit > twigcs-report.xml
after_script:
# Run it again so the output is visible in the job
- >
if [ "$CI_JOB_STATUS" != 'success' ]; then
php vendor/bin/twig-cs-fixer --no-interaction lint templates/
fi
artifacts:
expire_in: 1 week
reports:
junit: twigcs-report.xml
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
Stylelint - check code styling:
image: sumocoders/stylelint:latest
script:
- stylelint --output-file=stylelint-report.json --custom-formatter=stylelint-formatter-gitlab-code-quality-report .
after_script:
- >
if [ "$CI_JOB_STATUS" != 'success' ]; then
stylelint --color .
fi
artifacts:
expire_in: 1 week
reports:
codequality: stylelint-report.json
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
StandardJS - check code styling:
image: sumocoders/standardjs:latest
script:
- sh -c 'standard . | standard-gitlab --output-file standardjs-report.json --human-readable'
artifacts:
expire_in: 1 week
reports:
codequality: standardjs-report.json
stage: code quality
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
# Dependency Scanning section
NPM packages - check for vulnerabilities:
image: sumocoders/cli-tools-php85:latest
script:
- php bin/console importmap:audit --no-interaction --ansi
stage: dependency scanning
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
PHP packages - composer audit:
image: sumocoders/cli-tools-php85:latest
script:
- composer audit --ansi --no-interaction
stage: dependency scanning
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
# Outdated packages Scanning section
NPM packages - check for outdated packages:
image: sumocoders/cli-tools-php85:latest
script:
- php bin/console importmap:outdated --no-interaction --ansi
stage: outdated packages
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
PHP packages - composer outdated:
image: sumocoders/cli-tools-php85:latest
script:
- composer outdated --ansi --no-interaction --strict
stage: outdated packages
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
allow_failure: true
# Test section
PHPUnit - Run tests:
image: sumocoders/framework-php85:latest
services:
- mysql:8.0
before_script:
# Uncomment this if you need Chrome for PDF's
# or if you have integration tests that use Symfony Panther (https://github.com/symfony/panther)
# # install Chromium
# - apt-get --allow-releaseinfo-change update && apt-get install -y chromium
# # install Chromium Chromedriver
# - |
# curl -s -f -L -o /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE_97`/chromedriver_linux64.zip
# unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
script:
- php bin/console doctrine:migrations:migrate --env=test --no-interaction --allow-no-migration
# Uncomment this if you have fixtures that need to be loaded
# Make sure that you have installed doctrine/doctrine-fixtures-bundle
#- php bin/console doctrine:fixtures:load --env=test --no-interaction
- php vendor/bin/phpunit --color --testdox --log-junit phpunit-report.xml
artifacts:
reports:
junit: phpunit-report.xml
stage: test
interruptible: true
needs: [ "Install dependencies and build assets" ]
tags:
- docker
variables:
MYSQL_DATABASE: ci_test
MYSQL_ROOT_PASSWORD: root
DATABASE_URL: mysql://root:root@mysql:3306/ci_test?serverVersion=8.0
PANTHER_NO_SANDBOX: 1
PANTHER_WEB_SERVER_PORT: 9080
# Scheduled tasks section
Task - Update dependencies:
image: sumocoders/cli-tools-php85:latest
script:
- git config --global user.email "bot@sumocoders.be"
- git config --global user.name "Sumo Bot"
- git config --global push.autoSetupRemote true
- git remote set-url origin "https://bot:${GITLAB_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
- php bin/console sumo:maintenance:create-pr-for-outdated-dependencies --no-interaction --ansi
stage: scheduled tasks
needs: [ "Install dependencies and build assets" ]
rules:
- if: '$CI_PIPELINE_SOURCE =~ /schedule|web/'
tags:
- docker
# Deploy section
Deploy - to staging:
image: sumocoders/cli-tools-php85:latest
before_script:
# Add the private SSH key to the CI environment
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- php vendor/bin/dep deploy stage=staging
environment:
name: staging
url: https://$project.$client.php85.sumocoders.eu
stage: deploy
interruptible: false
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "staging"'
tags:
- docker
variables:
USER: "CI/CD gitlab-runner"
Deploy - to production:
image: sumocoders/cli-tools-php85:latest
before_script:
# Add the private SSH key to the CI environment
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- php vendor/bin/dep deploy stage=production
environment:
name: production
url: https://$productionUrl
stage: deploy
interruptible: false
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
tags:
- docker
variables:
USER: "CI/CD gitlab-runner"