-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
381 lines (344 loc) · 9.52 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
stages:
- pre-build
- test
- build
- deploy
- publish
- manual
default:
interruptible: true
artifacts:
expire_in: 30 days
tags:
- gitlab-org
variables:
PUPPETEER_VERSION: '11.0.0'
PUPPETEER_IMAGE: $CI_REGISTRY_IMAGE/puppeteer:$PUPPETEER_VERSION
# We want to utilize the faster SAST and Dependency Scanning which are not docker in docker
SAST_DISABLE_DIND: 'true'
DS_DISABLE_DIND: 'true'
# We only need javascript scanning, unfortunately our Danger code would lead to execution of ruby analysis as well
SAST_DEFAULT_ANALYZERS: 'nodejs-scan, eslint'
CYPRESS_CACHE_FOLDER: $CI_PROJECT_DIR/.cypress_cache/Cypress
include:
- template: Code-Quality.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
- template: License-Scanning.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml
- template: SAST.gitlab-ci.yml
- template: Secret-Detection.gitlab-ci.yml
- project: gitlab-org/frontend/frontend-build-images
file: /semantic-release/.gitlab-ci-template.rules.yml
- project: gitlab-org/frontend/untamper-my-lockfile
file: 'templates/merge_request_pipelines.yml'
# Ensure that the scanning is only executed on MRs and the default branch
# This potentially can be made obsolete once:
# https://gitlab.com/gitlab-org/gitlab/-/issues/217668 lands
.secure-jobs-config: &secure-jobs-config
needs: []
rules:
- when: always
gemnasium-dependency_scanning:
<<: *secure-jobs-config
code_quality:
<<: *secure-jobs-config
tags:
- gitlab-org-docker
license_scanning:
<<: *secure-jobs-config
eslint-sast:
<<: *secure-jobs-config
nodejs-scan-sast:
<<: *secure-jobs-config
secret_detection:
<<: *secure-jobs-config
container_scanning:
variables:
CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/puppeteer
CI_APPLICATION_TAG: $PUPPETEER_VERSION
needs: ['build_docker_image']
rules:
- when: always
.puppeteer:
image: $PUPPETEER_IMAGE
needs: ['build_docker_image']
.node:
image: node:16-buster
variables:
PUPPETEER_SKIP_DOWNLOAD: 'true'
# This is a cache template for caching node_modules
# As a cache key we are using a SHA of .gitlab-ci.yml and yarn.lock
# The latter is obvious, because it updates when we update dependencies
# The former is to invalidate caches, in case we touch our CI config, which
# could mean changing something in our caching logic
.cache-template: &cache-template
paths:
- node_modules/
- .cypress_cache/Cypress
key:
files:
- .gitlab-ci.yml
- yarn.lock
prefix: node_modules
.yarn_install:
before_script:
- yarn install --frozen-lockfile
cache:
<<: *cache-template
policy: pull
# Only start pipelines on Merge Requests or the default branch
workflow:
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
when: always
- if: $CI_MERGE_REQUEST_IID
when: always
- when: never
# Only run on GitLab UI default branches
.rules:gitlab-ui-default-branch:
rules:
- if: '$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "gitlab-org/gitlab-ui"'
# Only run on merge requests that come from GitLab UI or
# from forks when a GitLab UI team member triggered a pipeline
.if-gitlab-ui-mr: '$CI_MERGE_REQUEST_IID && $CI_PROJECT_PATH == "gitlab-org/gitlab-ui"'
.rules:gitlab-ui-mr:
rules:
- if: !reference [.if-gitlab-ui-mr]
.rules:gitlab-ui-mr-manual:
rules:
- if: !reference [.if-gitlab-ui-mr]
when: manual
allow_failure: true
build_docker_image:
variables:
DOCKER_HOST: tcp://docker:2375/
tags:
- gitlab-org-docker
image: docker:20.10.16
services:
- docker:20.10.16-dind
stage: pre-build
script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- ./bin/build-docker.sh
# As we are caching based on the contents of our CI config and dependency lock file
# We only need to execute when these change. However, we give a manual job as an escape hatch
populate_npm_cache:
extends: [.node, .yarn_install]
stage: pre-build
script:
- echo "successfully installed dependencies"
cache:
<<: *cache-template
policy: push
rules:
- changes:
- .gitlab-ci.yml
- yarn.lock
when: always
- when: never
danger-review:
variables:
DANGER_GITLAB_API_TOKEN: $GITLAB_TOKEN
rules:
- if: '$GITLAB_TOKEN && $CI_MERGE_REQUEST_IID'
when: always
image: registry.gitlab.com/gitlab-org/gitlab-build-images:danger
stage: test
needs: []
script:
- danger --fail-on-errors=true
build_package:
extends: [.node, .yarn_install]
variables:
TAR_ARCHIVE_NAME: gitlab-ui.$CI_COMMIT_REF_SLUG.tgz
needs: []
stage: build
script:
- yarn build
- yarn pack --filename $TAR_ARCHIVE_NAME
- DEPENDENCY_URL="$CI_PROJECT_URL/-/jobs/$CI_JOB_ID/artifacts/raw/$TAR_ARCHIVE_NAME"
- echo "The package.json dependency URL is $DEPENDENCY_URL"
- echo "DEPENDENCY_URL=$DEPENDENCY_URL" > build_package.env
artifacts:
when: always
reports:
dotenv: build_package.env
paths:
- dist
- src/scss/utilities.scss
- scss_to_js/scss_variables.*
- $TAR_ARCHIVE_NAME
build_storybook:
extends: [.node, .yarn_install]
needs: []
stage: build
script:
- apt-get update
- apt-get install -y brotli gzip
- echo "Building storybook..."
- yarn storybook-static
- mkdir public
- mv storybook/* public
# See: https://docs.gitlab.com/ee/user/project/pages/introduction.html#serving-compressed-assets
- echo "Compressing assets..."
- find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|json\|css\|svg\|xml\)$' -exec gzip -f -k {} \;
- find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|json\|css\|svg\|xml\)$' -exec brotli -f -k {} \;
- ls -alth public/
artifacts:
paths:
- public
lint:
extends: [.node, .yarn_install]
needs: []
stage: test
script:
- yarn build-scss-variables
- yarn eslint
- yarn prettier
- yarn stylelint
- yarn markdownlint
- >
grep -r -i '<style' --include \*.vue components
&& echo "Vue components should not contain <style tags"
&& exit 1
|| echo "No Vue component contains <style tags"
generate_utility_classes:
extends: [.node, '.yarn_install']
needs: []
stage: test
script:
- yarn generate-utilities
visual:
extends:
- .puppeteer
- .yarn_install
needs:
- build_docker_image
stage: test
script:
- yarn test:visual
rules:
- !reference ['.rules:gitlab-ui-default-branch', rules]
- if: '$CI_MERGE_REQUEST_IID'
when: manual
allow_failure: true
artifacts:
when: always
paths:
- tests/__image_snapshots__/
visual_minimal:
extends: [.puppeteer, .yarn_install]
needs:
- build_docker_image
stage: test
script:
- yarn test:visual:minimal
rules:
- if: '$CI_MERGE_REQUEST_IID'
when: always
artifacts:
when: always
paths:
- tests/__image_snapshots__/
integration_tests:
image: cypress/browsers:node14.17.0-chrome91-ff89
extends: [.node, .yarn_install]
needs: []
stage: test
script:
- yarn test:integration
artifacts:
when: on_failure
expire_in: 1 week
paths:
- cypress
unit_tests:
extends: [.node, .yarn_install]
needs: []
stage: test
script:
- yarn test:unit
update_screenshots:
extends:
- .puppeteer
- .yarn_install
- .rules:gitlab-ui-mr-manual
stage: manual
script:
- yarn test:visual:update
- ./bin/update-screenshots.sh
review:
extends:
- .rules:gitlab-ui-mr
stage: deploy
needs:
- build_storybook
script:
- rsync -av --delete public /srv/nginx/pages/$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
url: http://$CI_COMMIT_REF_SLUG.$APPS_DOMAIN
on_stop: review_stop
tags:
- nginx
- review-apps
- deploy
review_stop:
extends:
- .rules:gitlab-ui-mr-manual
stage: manual
needs:
- review
script:
- rm -rf public /srv/nginx/pages/$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
tags:
- nginx
- review-apps
- deploy
pages:
extends:
- .rules:gitlab-ui-default-branch
stage: deploy
needs:
- build_storybook
script:
- echo "Deploying to Pages"
artifacts:
paths:
- public
create_integration_branch:
extends:
- .node
- .rules:gitlab-ui-mr-manual
stage: manual
needs:
- build_package
script:
- INTEGRATION_BRANCH="gitlab-ui-integration-$CI_COMMIT_REF_NAME"
- git config --global user.email "[email protected]"
- git config --global user.name "GitLab Bot"
- git clone https://gitlab.com/gitlab-org/gitlab.git gitlab --depth=1
- cd gitlab
- (git remote set-branches origin '*' && git fetch origin $INTEGRATION_BRANCH && git checkout $INTEGRATION_BRANCH) || git checkout -b $INTEGRATION_BRANCH
- yarn add @gitlab/ui@$DEPENDENCY_URL
- git add package.json yarn.lock
- 'git commit -m "GitLab UI integration branch for $CI_COMMIT_REF_NAME"'
- git push -u https://gitlab-bot:[email protected]/gitlab-org/gitlab.git HEAD
publish_to_npm:
extends:
- .semantic-release
- .rules:gitlab-ui-default-branch
# We need to run `publish` after pages, so that pages will get deployed
# properly, as the publish-to-npm step will create a new commit and this
# could lead to a side-effect where pages don't get published because of
# the commit being made before `pages` had a chance to run
stage: publish
# This job doesn't use the DAG feature, because we don't want it to
# run in case another job in the previous stages fails
dependencies:
- build_package