-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
.gitlab-ci.yml
459 lines (409 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
stages:
- install
- build
- lint
- format
- setup
- test
- teardown
- release
# Fallback variables
variables:
PLAYWRIGHT_VERSION: $CI_JOB_IMAGE
TEST_ID: $CI_JOB_ID
CC_TEST_REPORTER_ID: $CC_TEST_REPORTER_ID
GCP_ZONE: us-central1-c
CONTAINER_NAME: gitlab-${CI_PIPELINE_ID}
# Cache Config
.cache:install:modules: &cacheinstallmodules
key:
files:
- yarn.lock
paths:
- node_modules
.cache:install:cc: &cachecodeclimate
key: codeclimate-0.11.1
paths:
- tmp/codeclimate
.cache:install:yarn: &cacheinstallyarn
key: yarn-$CI_JOB_IMAGE
paths:
- .yarn
.cache:nx: &cachenx
key:
files:
- yarn.lock
paths:
- .nx/cache
#Link and Install all required dependancies
install:
image: node:20-alpine
stage: install
variables:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
before_script:
- apk add --no-cache libc6-compat jq
- echo "PLAYWRIGHT_VERSION=$(yarn info @playwright/test -A --json | jq ".children.Version")" >> install.env
script:
- yarn
cache:
- <<: *cacheinstallmodules
policy: pull-push
- <<: *cacheinstallyarn
policy: pull-push
artifacts:
reports:
dotenv: install.env
build:
stage: build
image: node:20-alpine
needs:
- install
variables:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
- <<: *cachenx
policy: pull-push
before_script:
- apk add --no-cache libc6-compat git
script:
- yarn build
artifacts:
paths:
- packages/core/dist/
- packages/cli/dist/
- packages/rest/dist/
- packages/requester-utils/dist/
expire_in: 2d
# Lint all code, tests and supporting documentation (README, CHANGELOG etc)
lint:
stage: lint
image: node:20-alpine
needs:
- install
variables:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
- <<: *cachenx
policy: pull-push
before_script:
- apk add --no-cache libc6-compat
script: yarn lint
format:
stage: format
image: node:20-alpine
needs:
- install
variables:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
before_script:
- apk add --no-cache libc6-compat
script: yarn format
## Test Setup
test:unit:setup:
stage: setup
image: alpine/curl
needs: []
script:
- mkdir -p tmp/codeclimate
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/codeclimate/cc-test-reporter
- ls tmp/codeclimate/
- chmod +x ./tmp/codeclimate/cc-test-reporter
cache:
- <<: *cachecodeclimate
policy: pull-push
test:live:setup:
stage: setup
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
needs: []
timeout: 15m
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
allow_failure: false
- if: $CI_COMMIT_BRANCH == "next" || $CI_COMMIT_BRANCH =~ /^pr-[0-9]+$/
when: manual
allow_failure: true
variables:
GITLAB_PERSONAL_ACCESS_TOKEN: gitbeaker
GITLAB_VERSION: 16.11.3-ce.0
GITLAB_ROOT_PASSWORD: gitbeaker
before_script:
- apk add jq curl envsubst
- gcloud components install beta -q
script:
- echo $GCLOUD_SERVICE_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
- gcloud --quiet config set project ${GOOGLE_PROJECT_ID} --no-user-output-enabled
- envsubst < scripts/startup.sh > scripts/startup_filled.sh
- |
GITLAB_HOST="$(gcloud beta compute instances create $CONTAINER_NAME \
--project gitbeaker \
--machine-type=e2-highmem-2 \
--boot-disk-size=25GB \
--zone=$GCP_ZONE \
--tags http-server \
--metadata-from-file startup-script=scripts/startup_filled.sh \
--image-family=debian-12 \
--image-project=debian-cloud \
--format='get(networkInterfaces[0].accessConfigs[0].natIP)'
2>/dev/null \
)"
- GITLAB_URL="http://${GITLAB_HOST}"
- echo "GITLAB_URL=${GITLAB_URL}" >> intergration.env
- echo "GITLAB_PERSONAL_ACCESS_TOKEN=${GITLAB_PERSONAL_ACCESS_TOKEN}" >> intergration.env
- echo "Waiting for service to start"
- sleep 240
- attempt=1
- |
while [[ "$(curl --fail --silent -X GET "$GITLAB_URL/-/readiness?all=1" --insecure | jq -r '.master_check[0].status')" != "ok" ]]; do
echo "Polling Attempt: $attempt - Gitlab service is not alive yet";
sleep 10;
((attempt++));
done
- echo "Service is up and running"
artifacts:
reports:
dotenv: intergration.env
# Tests Templates
.test:base:
stage: test
image: node:20-alpine
needs:
- install
variables:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
- <<: *cachenx
policy: pull-push
before_script:
- apk add --no-cache libc6-compat
.test:unit:base:
extends: .test:base
needs:
- install
- test:unit:setup
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
- <<: *cachecodeclimate
policy: pull
- <<: *cachenx
policy: pull-push
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
before_script:
- apk add --no-cache libc6-compat git
after_script:
- cd $PKG_PATH
- ../../tmp/codeclimate/cc-test-reporter format-coverage -t lcov -o coverage/cc-coverage.json coverage/lcov.info
artifacts:
when: always
paths:
- $PKG_PATH/coverage/cc-coverage.json
reports:
junit: $PKG_PATH/reports/*junit.xml
coverage_report:
coverage_format: cobertura
path: $PKG_PATH/coverage/cobertura-coverage.xml
.test:types:base:
extends: .test:base
needs:
- build
.test:integration:base:
extends: .test:base
needs:
- build
.test:e2e:base:
extends: .test:base
only:
refs:
- /^pr-[0-9]+$/
- main
- next
needs:
- build
- test:live:setup
when: on_success
## Unit Tests
test:unit:utils:
extends: .test:unit:base
script: yarn test:unit --projects=@gitbeaker/requester-utils
variables:
PKG_PATH: 'packages/requester-utils'
test:unit:core:
extends: .test:unit:base
script: yarn test:unit --projects=@gitbeaker/core
variables:
PKG_PATH: 'packages/core'
test:unit:rest:
extends: .test:unit:base
script: yarn test:unit --projects=@gitbeaker/rest
variables:
PKG_PATH: 'packages/rest'
test:unit:cli:
extends: .test:unit:base
script: yarn test:unit --projects=@gitbeaker/cli
variables:
PKG_PATH: 'packages/cli'
## Types Tests
test:types:utils:
extends: .test:types:base
variables:
PKG_PATH: 'packages/requester-utils'
script: yarn test:types --projects=@gitbeaker/requester-utils
test:types:core:
extends: .test:types:base
variables:
PKG_PATH: 'packages/core'
script: yarn test:types --projects=@gitbeaker/core
test:types:rest:
extends: .test:types:base
variables:
PKG_PATH: 'packages/rest'
script: yarn test:types --projects=@gitbeaker/rest
## Integration Tests
test:integration:rest:
extends: .test:integration:base
image: mcr.microsoft.com/playwright:v1.45.1-focal
before_script:
# reinstall swc due to missing binding for ubuntu image
- yarn add @swc/core
script: yarn test:integration --projects=@gitbeaker/rest
test:integration:core:
extends: .test:integration:base
script: yarn test:integration --projects=@gitbeaker/core
## End-to-End Tests
test:e2e:rest:
extends: .test:e2e:base
image: mcr.microsoft.com/playwright:v1.45.1-focal
allow_failure: true
before_script:
# reinstall swc due to missing binding for ubuntu image
- yarn add @swc/core
script: yarn test:e2e --projects=@gitbeaker/rest
test:e2e:cli:
extends: .test:e2e:base
allow_failure: true
script: yarn test:e2e --projects=@gitbeaker/cli
# Teardown
test:unit:teardown:
stage: teardown
image: alpine/curl
except:
refs:
- /^pr-[0-9]+$/
needs:
- test:unit:utils
- test:unit:core
- test:unit:rest
- test:unit:cli
when: always
cache:
- <<: *cachecodeclimate
policy: pull
before_script:
- mkdir coverage
- ls tmp/codeclimate
script:
- ./tmp/codeclimate/cc-test-reporter sum-coverage packages/*/coverage/cc-coverage.json -p 4 -o ./coverage/codeclimate.json
- ./tmp/codeclimate/cc-test-reporter upload-coverage -i ./coverage/codeclimate.json
test:live:teardown:
stage: teardown
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
needs:
- test:e2e:rest
- test:e2e:cli
only:
refs:
- /^pr-[0-9]+$/
- main
- next
variables:
GIT_STRATEGY: none
script:
- echo $GCLOUD_SERVICE_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
- gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
- gcloud compute instances delete $CONTAINER_NAME --zone=$GCP_ZONE
# Releases
.release:base:
stage: release
image: node:20-alpine
variables:
GIT_STRATEGY: clone
GIT_DEPTH: 0
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
needs:
- build # CHECKME: Needed for the artifacts
- test:unit:utils
- test:unit:core
- test:unit:cli
- test:unit:rest
- test:types:utils
- test:types:core
- test:types:rest
- test:integration:rest
- test:integration:core
- test:e2e:cli
- test:e2e:rest
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
before_script:
- apk add --no-cache libc6-compat git openssh
- npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
- git config --global user.name "Autobot"
- git config --global user.email "[email protected]"
- git remote set-url origin https://jdalrymple:${GITHUB_TOKEN}@github.com/jdalrymple/gitbeaker.git
- git branch $CI_COMMIT_BRANCH HEAD
- git checkout $CI_COMMIT_BRANCH
- echo 'Ensure build files are present'
- ls -A packages/requester-utils/dist
- ls -A packages/core/dist
- ls -A packages/rest/dist
- ls -A packages/cli/dist
## Canary or RC Special Releases
release:special:
extends: .release:base
only:
refs:
- /^pr-[0-9]+$/
script:
- echo "Checking for special release..."
- |
if [[ $CI_COMMIT_BRANCH =~ ^pr-[0-9]*$ ]]; then
pr_id="${CI_COMMIT_BRANCH//[!0-9]/}"
export CI_MERGE_REQUEST_ID=$pr_id
export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_COMMIT_BRANCH
labels=$(yarn auto label --pr $pr_id)
if [[ "$labels" =~ "release:canary" ]]; then
yarn release:canary
fi
fi
## Production
release:
extends: .release:base
only:
refs:
- main
- next
script: yarn release