-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
339 lines (308 loc) · 9.11 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
# Copyright 2017-2024 IQRF Tech s.r.o.
# Copyright 2019-2024 MICRORISC s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
image: iqrftech/iqrf-gateway-webapp:tests-bookworm
stages:
- build-docker-testing
- test
- coding-style
- sentry-release
- jsonnet
- build-docker
- deploy-docs
variables:
COMPOSER_CACHE_DIR: temp/composer/cache
cache:
paths:
- temp/composer/cache
.base_template: &base_template
tags:
- linux
- amd64
.coding-style_template: &coding-style_template
stage: coding-style
needs: []
<<: *base_template
.npm_template: &npm_template
before_script:
- pnpm config set store-dir .pnpm-store
- pnpm config set registry http://nexus.iqrf.internal/repository/npmjs.org-proxy/
- pnpm install
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .pnpm-store
.test_template: &test_template
stage: test
needs: []
retry: 2
<<: *base_template
.sentry-version_template: &sentry-version_template
stage: sentry-release
script:
- sentry-cli releases new -p iqrf-gateway-webapp -p iqrf-gateway-webapp-frontend ${VERSION}
- sentry-cli releases set-commits --auto ${VERSION}
<<: *base_template
.ssh_template: &ssh_template
before_script:
- 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
<<: *base_template
.docker_template:
image: docker:stable
services:
- docker:dind
stage: build-docker
before_script:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
script:
- docker build -f $DOCKER_FILE -t $DOCKER_IMAGE:$DOCKER_TAG .
- docker push $DOCKER_IMAGE:$DOCKER_TAG
tags:
- linux, amd64, docker
variables:
DOCKER_IMAGE: iqrftech/iqrf-gateway-webapp
.docker_template_testing:
extends: .docker_template
allow_failure: true
stage: build-docker-testing
only:
refs:
- master
- schedules
tags:
- linux, docker, amd64
build-docker:tests:
extends: .docker_template_testing
only:
- schedules
variables:
DOCKER_FILE: docker/tests/bookworm.Dockerfile
DOCKER_TAG: tests-bookworm
test:
before_script:
- composer install --no-progress
- update-alternatives --set php /usr/bin/php${PHP_VERSION}
script:
- vendor/bin/tester -p phpdbg${PHP_VERSION} -c ./tests/php.ini -s ./tests
after_script:
- 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'
parallel:
matrix:
- PHP_VERSION:
- '8.1'
- '8.2'
- '8.3'
<<: *test_template
newman:
stage: test
image: docker:latest
needs: []
services:
- docker:dind
before_script:
- apk add --no-cache docker-compose
script:
- docker-compose -f api-testing.docker-compose.yml up --build --abort-on-container-exit
tags:
- linux, docker, amd64
build:js:
script:
- 'if [[ "${PACKAGE}" == "api-client" || "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/daemon-utils build; fi'
- 'if [[ "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/api-client build; fi'
- pnpm --dir packages/${PACKAGE} run build
parallel:
matrix:
- PACKAGE:
- api-client
- daemon-utils
- frontend
- frontend3
<<: *test_template
<<: *npm_template
coverage:
before_script:
- composer install --no-progress
- update-alternatives --set php /usr/bin/php8.1
- vendor/bin/tester -c ./tests/php-coverage.ini --info
script:
- vendor/bin/tester -c ./tests/php-coverage.ini -o none -o junit:junit.xml --coverage ./coverage.html --coverage-src ./app ./tests
allow_failure: true
coverage: '/^\d+% covered/'
artifacts:
paths:
- 'coverage.html'
expire_in: 2 weeks
reports:
junit:
- junit.xml
<<: *test_template
coverage:js:
<<: *test_template
<<: *npm_template
before_script:
- !reference [.npm_template, before_script]
- 'if [[ "${PACKAGE}" == "api-client" || "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/daemon-utils build; fi'
- 'if [[ "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/api-client build; fi'
script:
- pnpm --dir packages/${PACKAGE} coverage:unit
allow_failure: true
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
artifacts:
paths:
- 'packages/${PACKAGE}/coverage/'
expire_in: 2 weeks
when: always
reports:
junit:
- packages/${PACKAGE}/junit.xml
parallel:
matrix:
- PACKAGE:
- api-client
- frontend
- frontend3
coding-style:
script:
- make cc
<<: *coding-style_template
doctrine_mapping:
before_script:
- composer install --no-progress
script:
- bin/manager orm:validate-schema --skip-sync
<<: *coding-style_template
phpstan:
retry: 2
before_script:
- composer install --no-progress
script:
- NETTE_TESTER_RUNNER=1 php vendor/bin/phpstan analyse -c phpstan.neon
<<: *coding-style_template
eslint:
<<: *coding-style_template
<<: *npm_template
before_script:
- !reference [.npm_template, before_script]
- 'if [[ "${PACKAGE}" == "api-client" || "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/daemon-utils build; fi'
- 'if [[ "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/api-client build; fi'
script:
- pnpm --dir packages/${PACKAGE} run lint:js
parallel:
matrix:
- PACKAGE:
- api-client
- daemon-utils
- frontend
- frontend3
stylelint:
script:
- pnpm --dir packages/${PACKAGE} lint:css
parallel:
matrix:
- PACKAGE:
- frontend
- frontend3
<<: *coding-style_template
<<: *npm_template
qa:
before_script:
- composer install --no-progress
script:
- vendor/bin/codesniffer --runtime-set php_version 80100 app bin tests
<<: *coding-style_template
# Sentry version
sentry-version:
before_script:
- export VERSION=`jq -r .version version.json`"~${CI_PIPELINE_ID}"
except:
- tags
<<: *sentry-version_template
sentry-version_release:
before_script:
- export VERSION=`jq -r .version version.json`
only:
- tags
<<: *sentry-version_template
# Jsonnet
jsonnet-build:
image: alpine:latest
stage: jsonnet
script:
- apk add -U jsonnet
- jsonnet -o .gitlab/packages.yml .gitlab/packages.jsonnet
artifacts:
paths:
- .gitlab/packages.yml
jsonnet-trigger-packages:
stage: jsonnet
needs:
- jsonnet-build
trigger:
forward:
pipeline_variables: true
include:
- artifact: .gitlab/packages.yml
job: jsonnet-build
strategy: depend
deploy:docs:openapi:
stage: deploy-docs
environment:
name: apidocs
url: https://apidocs.iqrf.org/openapi/iqrf-gateway-webapp/
only:
- master
script:
- composer install --no-progress
- bin/manager open-api:specification > api.json
- ssh [email protected] "rm -rf /data/nginx/apidocs/openapi/iqrf-gateway-webapp/api.json /data/nginx/apidocs/openapi/iqrf-gateway-webapp/schemas/"
- rsync -hrvz --delete -e ssh api.json [email protected]:/data/nginx/apidocs/openapi/iqrf-gateway-webapp/api.json
- rsync -hrvz --delete -e ssh api/schemas/* [email protected]:/data/nginx/apidocs/openapi/iqrf-gateway-webapp/schemas/
<<: *ssh_template
deploy-docs:typedoc:
<<: *base_template
<<: *npm_template
<<: *ssh_template
stage: deploy-docs
environment:
name: apidocs
url: https://apidocs.iqrf.org/${DEPLOY_DIR}/
only:
- master
before_script:
- !reference [.npm_template, before_script]
- !reference [.ssh_template, before_script]
- 'if [[ "${PACKAGE}" == "api-client" || "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/daemon-utils build; fi'
- 'if [[ "${PACKAGE}" == "frontend" || "${PACKAGE}" == "frontend3" ]]; then pnpm --dir packages/api-client build; fi'
script:
- pnpm --dir packages/${PACKAGE} docs
- ssh [email protected] "rm -rf /data/nginx/apidocs/${DEPLOY_DIR}/*"
- rsync -hrvz --delete -e ssh packages/${PACKAGE}/docs/* [email protected]:/data/nginx/apidocs/${DEPLOY_DIR}/
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .pnpm-store
parallel:
matrix:
- PACKAGE: api-client
DEPLOY_DIR: js/iqrf-gateway-webapp-client
- PACKAGE: daemon-utils
DEPLOY_DIR: js/iqrf-gateway-daemon-utils
include:
- template: Code-Quality.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml