-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
393 lines (358 loc) · 10.7 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
# NOTE: Static Sites often want to optimize for fast build and deploy
# pipeline times, so changes are published as quickly as possible.
# Therefore, this default config includes optional variables, settings,
# and caching, which help minimize job run times. For example,
# disabling support for git LFS and submodules. There are also retry
# and reliability settings which help prevent false build failures
# due to occasional infrastructure availability problems. These are
# all documented inline below, and can be changed or removed as
# necessary, depending on the requirements for your repo or project.
###################################
#
# GENERAL/DEFAULT CONFIG:
#
###################################
stages:
- sync
- build
- deploy
- notify
- maintenance
include:
- component: gitlab.com/components/secret-detection/secret-detection@~latest
- component: gitlab.com/gitlab-org/components/danger-review/[email protected]
inputs:
job_stage: build
default:
image: alpine:latest
interruptible: true # All jobs are interruptible by default
# The following 'retry' configuration settings may help avoid false build failures
# during brief problems with CI/CD infrastructure availability
retry:
max: 2 # This is confusing but this means "3 runs at max".
when:
- unknown_failure
- api_failure
- runner_system_failure
- job_execution_timeout
- stuck_or_timeout_failure
tags:
- saas-linux-medium-amd64
cache:
- key:
files:
- go.mod
- go.sum
paths:
- $GOPATH/pkg/mod/
- key:
files:
- package.json
- package-lock.json
paths:
- $NPM_CACHE
- key:
files:
- go.sum
paths:
- $HUGO_CACHEDIR
variables:
# NOTE: The following PERFORMANCE and RELIABILITY variables are optional, but may
# improve performance of larger repositories, or improve reliability during
# brief problems with CI/CD infrastructure availability
### PERFORMANCE ###
# GIT_* variables to speed up repo cloning/fetching
GIT_DEPTH: 0
# Disabling LFS and submodules will speed up jobs, because runners don't have to perform
# the submodule steps during repo clone/fetch. These settings can be deleted if you are using
# LFS or submodules.
GIT_LFS_SKIP_SMUDGE: 1
GIT_SUBMODULE_STRATEGY: none
# Speed up artifact compression and upload
# https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/2684
FF_USE_FASTZIP: 1
ARTIFACT_COMPRESSION_LEVEL: fast
### RELIABILITY ###
# Reduce potential of flaky builds via https://docs.gitlab.com/ee/ci/yaml/#job-stages-attempts variables
GET_SOURCES_ATTEMPTS: 3
ARTIFACT_DOWNLOAD_ATTEMPTS: 3
RESTORE_CACHE_ATTEMPTS: 3
EXECUTOR_JOB_SECTION_ATTEMPTS: 3
### BUILD / PAGES DEFAULTS **
ENVIRONMENT: 'production'
HUGO_BASEURL: 'https://handbook.gitlab.com/'
PAGES_PREFIX: ""
### TOOLING ###
# Specify versions of tools used in pipelines
HUGO_VERSION: '0.139.3'
HUGO_IMAGE: "registry.gitlab.com/pages/hugo/hugo_extended:$HUGO_VERSION"
HUGOLINT_VERSION: '1.8.1'
MARKDOWNLINT_VERSION: '0.15.0'
VALE_VERSION: '3.9.1'
### CACHE DEPENDENCIES ###
GOPATH: $CI_PROJECT_DIR/.GOPATH
NPM_CACHE: $CI_PROJECT_DIR/.npm
HUGO_CACHEDIR: $CI_PROJECT_DIR/.hugo_cache
.default-branch: &default-branch
if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $BUILD_AND_TEST_ONLY != "true"
.merge-request-only: &merge-request-only
if: $CI_PIPELINE_SOURCE == 'merge_request_event'
.merge-request-or-tag: &merge-request-or-tag
if: '$CI_MERGE_REQUEST_IID || $CI_COMMIT_TAG'
.scheduled-pipeline: &scheduled-pipeline
if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_DEPLOY == "true"'
.build-and-test-only: &build-and-test-only
if: '$BUILD_AND_TEST_ONLY == "true"'
.is-fork: &is-fork
if: '$CI_PROJECT_ID != "42817607"'
.scheduled-update: &scheduled-update
if: '$CI_PIPELINE_SOURCE == "schedule" && $RUN_TYPE == "count-update"'
###################################
#
# INTERRUPTION PROTECTION
#
###################################
dont-interrupt-me:
stage: sync
interruptible: false
script:
- echo "This jobs makes sure this pipeline won't be interrupted! See https://docs.gitlab.com/ee/ci/yaml/#interruptible."
variables:
GIT_STRATEGY: none
rules:
- if: $CI_PIPELINE_SOURCE == "pipeline"
###################################
#
# BUILD STAGE
#
###################################
build:
image: $HUGO_IMAGE
stage: build
script:
- echo -e "\e[0Ksection_start:`date +%s`:group1\r\e[0KGroup 1"
- apk update
- echo -e "\e[0Ksection_end:`date +%s`:group1\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group2\r\e[0KGroup 2"
- apk upgrade
- echo -e "\e[0Ksection_end:`date +%s`:group2\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group3\r\e[0KGroup 3"
- apk add go npm yq curl coreutils sed
- echo -e "\e[0Ksection_end:`date +%s`:group3\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group4\r\e[0KGroup 4"
- ./scripts/sync-data.sh
- echo -e "\e[0Ksection_end:`date +%s`:group4\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group5\r\e[0KGroup 5"
- npm ci --cache $NPM_CACHE
- echo -e "\e[0Ksection_end:`date +%s`:group5\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group6\r\e[0KGroup 6"
- hugo --enableGitInfo
- echo -e "\e[0Ksection_end:`date +%s`:group6\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:group7\r\e[0KGroup 7"
- find "public" -type f -name '*.html' -exec sed -i -e "s/content-sites\/handbook\/${PAGES_PREFIX}\/content-sites\/handbook\/${PAGES_PREFIX}/content-sites\/handbook\/${PAGES_PREFIX}/g" {} +
- echo -e "\e[0Ksection_end:`date +%s`:group7\r\e[0K"
artifacts:
paths:
- public
rules:
- <<: *default-branch
- <<: *build-and-test-only
- <<: *merge-request-only
variables:
PAGES_PREFIX: 'mr$CI_MERGE_REQUEST_IID'
HUGO_BASEURL: "${CI_PAGES_URL}/${PAGES_PREFIX}"
###################################
#
# DEPLOY STAGE
#
###################################
pages:
stage: deploy
dependencies: [build]
environment:
name: $ENVIRONMENT
url: $HUGO_BASEURL
variables:
GIT_STRATEGY: none
pages:
path_prefix: "$PAGES_PREFIX"
artifacts:
paths:
- public
script:
- echo "Pages accessible through ${CI_PAGES_URL}/${PAGES_PREFIX}"
rules:
- <<: *default-branch
- <<: *scheduled-pipeline
- if: '$CI_MERGE_REQUEST_LABELS =~ /deploy-review-app-always/'
variables:
PAGES_PREFIX: 'mr$CI_MERGE_REQUEST_IID'
ENVIRONMENT: 'review/mr$CI_MERGE_REQUEST_IID'
HUGO_BASEURL: "${CI_PAGES_URL}/${PAGES_PREFIX}/"
- <<: *merge-request-only
variables:
PAGES_PREFIX: 'mr$CI_MERGE_REQUEST_IID'
ENVIRONMENT: 'review/mr$CI_MERGE_REQUEST_IID'
HUGO_BASEURL: "${CI_PAGES_URL}/${PAGES_PREFIX}/"
when: manual
allow_failure: true
####################################
##
## TEST STAGE
##
####################################
markdownlint:
image:
name: davidanson/markdownlint-cli2:v${MARKDOWNLINT_VERSION}
entrypoint: [""]
docker:
user: root
stage: build
needs: []
variables:
FORCE_COLOR: 1
before_script:
- npm install chalk terminal-link
script:
- apk add git
- sh ./scripts/markdownlint.sh
rules:
- <<: *merge-request-or-tag
- <<: *is-fork
artifacts:
when: always
expire_in: 1 month
paths:
- markdownlint-cli2-codequality.json
reports:
codequality: markdownlint-cli2-codequality.json
vale:
image:
name: jdkato/vale:v${VALE_VERSION}
entrypoint: [""]
docker:
user: root
stage: build
needs: []
script:
- apk add git
- sh ./scripts/vale.sh
rules:
- <<: *merge-request-or-tag
- <<: *is-fork
artifacts:
when: always
expire_in: 1 month
paths:
- vale-codequality.json
reports:
codequality: vale-codequality.json
handbooklint:
image:
name: gitlab/glab
entrypoint: [""]
stage: build
needs: []
before_script:
- apk update
- apk upgrade
- apk add jq sed bash
script:
- bash ./scripts/handbook-lint.sh
rules:
- <<: *merge-request-or-tag
- <<: *is-fork
artifacts:
when: always
expire_in: 1 month
paths:
- handbook-codequality.json
reports:
codequality: handbook-codequality.json
check_path_change:
stage: build
image:
name: gitlab/glab
entrypoint: [""]
before_script:
- apk add git bash jq
script:
- bash ./scripts/check-path-change.sh
rules:
- if: $CI_MERGE_REQUEST_LABELS =~ /skip-path-check/
when: never
- <<: *merge-request-or-tag
hugolint:
stage: build
needs: []
rules:
- <<: *build-and-test-only
- <<: *is-fork
- <<: *default-branch
- <<: *merge-request-or-tag
image:
name: registry.gitlab.com/gitlab-com/content-sites/handbook-tools/hugolint:v${HUGOLINT_VERSION}
script:
- hugolint linkcheck --exclude .hugolint.exclude --format=json $(find content -type f -name '*.md' | grep -v ' ') >linkcheck.json
- hugolint missinglinks --num 30 $(find content -name '*.md' | grep -v ' ') 2>/dev/null | tee missinglinks.txt
- |
# Compare with target branch when running as a merge request pipeline.
if [ "${CI_PIPELINE_SOURCE}" == "merge_request_event" ]; then
hugolint codequality latest --artifact 'linkcheck.json' >'latest.json'
hugolint codequality diff --exit-code 'latest.json' 'linkcheck.json'
fi
artifacts:
when: always
expire_in: 1 month
paths:
- linkcheck.json
- missinglinks.txt
reports:
codequality: linkcheck.json
secret_detection:
stage: build
needs: []
dependencies: [] # Don't download artifacts, especially `./public/`
rules:
- <<: *build-and-test-only
- <<: *merge-request-or-tag
- <<: *is-fork
####################################
##
## NOTIFY STAGE
##
####################################
post_comment_on_failure:
needs: ["markdownlint", "handbooklint", "vale", "hugolint"]
when: on_failure
stage: notify
image:
name: gitlab/glab
entrypoint: [""]
before_script:
- apk add jq sed bash
script:
- bash ./scripts/parse-codequality-report.sh -r ./codequality.json > msg.txt
- bash ./scripts/post-comment.sh "$(cat msg.txt)"
rules:
- <<: *merge-request-or-tag
notify_slack_on_build_failures:
when: on_failure
stage: notify
script: ./scripts/send-failure-notification-to-slack.sh
rules:
- <<: *is-fork
when: never
- <<: *default-branch
####################################
##
## MAINTENANCE STAGE
##
####################################
update_counts:
stage: maintenance
before_script:
- apk add git
script: ./scripts/update-counts.sh
rules:
- <<: *scheduled-update