forked from jdalrymple/gitbeaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
414 lines (378 loc) · 10.4 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
stages:
- install
- build
- lint
- format
- test
- release
# Fallback variables
variables:
PLAYWRIGHT_VERSION: $CI_JOB_IMAGE
TEST_ID: $CI_JOB_ID
CC_TEST_REPORTER_ID: $CC_TEST_REPORTER_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:
- node_modules/.cache/nx
#Link and Install all required dependancies
install:
image: node:20-alpine
stage: install
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
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
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
cache:
- <<: *cacheinstallmodules
policy: pull
- <<: *cacheinstallyarn
policy: pull
before_script:
- apk add --no-cache libc6-compat
script: yarn format
# Tests
.test:base:
stage: test
image: node:20-alpine
needs:
- install
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
only:
refs:
- /^pr-[0-9]+$/
- main
- next
needs:
- install
- test:live:setup
.test:e2e:base:
extends: .test:integration:base
needs:
- build
- test:live:setup
## Unit Tests
test:unit:setup:
stage: test
image: alpine/curl
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: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'
test:unit:teardown:
stage: test
image: alpine/curl
except:
refs:
- /^pr-[0-9]+$/
needs:
- test:unit:utils
- test:unit:core
- test:unit:rest
- test:unit:cli
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
## 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
## Live Test Setup and Clean Up
test:live:setup:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
stage: test
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: $CI_COMMIT_BRANCH == "next" || $CI_COMMIT_BRANCH =~ /^pr-[0-9]+$/
when: manual
needs:
- build
allow_failure: false
variables:
GITLAB_PERSONAL_ACCESS_TOKEN: gitbeaker
CONTAINER_NAME: gitlab-${CI_PIPELINE_ID}
GITLAB_ROOT_PASSWORD: gitbeaker
before_script:
- apk add jq curl
script:
- echo $GCLOUD_SERVICE_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
- gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
- |
GITLAB_URL=$(gcloud compute instances create-with-container $CONTAINER_NAME \
--project gitbeaker \
--machine-type=e2-standard-2 \
--zone=northamerica-northeast1-b \
--tags http-server,https-server \
--container-image docker.io/gitlab/gitlab-ce:latest \
--container-command '/bin/sh' \
--container-arg="-c" \
--container-arg="printf '#!/usr/bin/env ruby \nu = User.first \nu.admin = true \nu.save! \nt = PersonalAccessToken.new({ user: u, name: \"gitbeaker\", scopes: [\"api\", \"read_user\"]}) \nt.expires_at = 365.days.from_now \nt.set_token(ENV[\"PERSONAL_ACCESS_TOKEN\"]) \nt.save! \nputs t.token\n' > /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/40_access_token.rb && /assets/wrapper" \
--container-env ^~^GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD}~PERSONAL_ACCESS_TOKEN=${GITLAB_PERSONAL_ACCESS_TOKEN}~GITLAB_OMNIBUS_CONFIG="gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0', '172.17.0.1'];" \
--metadata SELF_DESTRUCT_INTERVAL_MINUTES=15 \
--metadata-from-file startup-script=./scripts/shutdown.sh \
--format='get(networkInterfaces[0].accessConfigs[0].natIP)'\
| head -2 | tail -1 )
- GITLAB_URL="http://${GITLAB_URL}"
- echo "GITLAB_URL=${GITLAB_URL}" >> intergration.env
- echo "GITLAB_PERSONAL_ACCESS_TOKEN=${GITLAB_PERSONAL_ACCESS_TOKEN}" >> intergration.env
- cat intergration.env
- echo "Waiting for service to start"
- |
sleep 180
while [[ "$(curl --fail --silent -X GET "$GITLAB_URL/-/readiness?all=1" --insecure | jq -r '.master_check[0].status')" != "ok" ]]; do echo "Polling service - not alive yet"; sleep 10; done;
echo "Service is up and running!"
artifacts:
reports:
dotenv: intergration.env
test:live:teardown:
stage: test
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
needs:
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
when: always
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 gitlab-${CI_PIPELINE_ID} --zone=northamerica-northeast1-b
## Integration Tests
test:integration:rest:
extends: .test:integration:base
script: yarn test:integration --projects=@gitbeaker/rest
## End-to-End Tests
test:e2e:core:
extends: .test:e2e:base
script: yarn test:e2e --projects=@gitbeaker/core
test:e2e:rest:
extends: .test:e2e:base
image: mcr.microsoft.com/playwright:v1.40.0-focal
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
script: yarn test:e2e --projects=@gitbeaker/cli
# Releases
.release:base:
stage: release
image: node:20-alpine
variables:
GIT_STRATEGY: clone
GIT_DEPTH: 0
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 "ci@gitlab.com"
- 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
## Canary or RC Special Releases
release:special:
extends: .release:base
needs:
- build
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
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
needs:
- build
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
- test:unit:teardown
only:
refs:
- main
- next
script: yarn release