-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
565 lines (517 loc) · 16.6 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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# ---------------------------------------------------------------
# Global
# ---------------------------------------------------------------
# default image
image: node:18-slim
stages:
- environment
- build
- package
- release
- deploy
workflow:
rules:
- changes:
- docker/**/Dockerfile
- src/**/*
- android/**/*
- .gitlab-ci.yml
- package.json
- package-lock.json
- tsconfig*.json
- angular.json
- scripts/**/*
# ---------------------------------------------------------------
# Global variables
# ---------------------------------------------------------------
variables:
CI_BUILD_IMAGE: $CI_REGISTRY_IMAGE/build:develop
CI_BUILD_ELECTRON_IMAGE: electronuserland/builder:18-wine
BUILD_CACHE_DIR: /tmp/.build-cache
BUILD_ENVIRONMENT: prod
DOCKER_BUILDKIT: 1
ARTIFACT_ZIP_FILES: ${OUTPUT_DIR}/${CI_PROJECT_NAME}-*.zip
ENV_FILE: variables.env
IONIC_CLI_VERSION: 7.2.0
ANGULAR_CLI_VERSION: 17.3.5
# ---------------------------------------------------------------
# Jobs templates
# ---------------------------------------------------------------
.configure-git-template: &git-setup
tags: [ kepler ]
before_script:
- echo "--- Fetch origin"
- git remote set-url origin "https://gitlab+access-token:${CI_ACCESS_TOKEN}@git.duniter.org/${CI_PROJECT_PATH}.git"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git fetch origin
.docker:
image: docker:latest
tags: [ kepler ]
services:
- docker:dind
before_script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
after_script:
- docker logout ${CI_REGISTRY}
allow_failure: false
.configure-android-template: &android-setup
image: ${CI_BUILD_IMAGE}
tags: [ kepler ]
before_script:
- if [[ -n ${APP_VERSION} ]]; then git fetch origin ; git checkout ${APP_VERSION} ; fi
# Get project dependencies
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
# Install Android environment (e.g. will create local.properties)
- mkdir -p .local
- npm run android:install
- source .local/env.sh
# Prepare local.properties file
- echo "--- Preparing Android 'local.properties' file ..."
- if [[ "_${ANDROID_SDK_ROOT}" == "_" ]]; then echo "Missing required variable ANDROID_SDK_ROOT. Cannot prepare Android 'local.properties' file"; exit 1; fi
- echo 'sdk.dir=${ANDROID_SDK_ROOT}' > android/local.properties
# Prepare for signing
- echo "--- Preparing Android 'release-signing.properties' file ..."
- if [[ "$BUILD_ENVIRONMENT" == "prod" && "_${ANDROID_STORE_PASSWORD}" == "_" ]]; then echo "Missing required variable ANDROID_STORE_PASSWORD. This variable is only available on protected branch."; exit 1; fi
- if [[ "$BUILD_ENVIRONMENT" == "prod" && "_${ANDROID_KEY_ALIAS}" == "_" ]]; then echo "Missing required variable ANDROID_KEY_ALIAS"; exit 1; fi
- if [[ "$BUILD_ENVIRONMENT" == "prod" && "_${ANDROID_KEY_PASSWORD}" == "_" ]]; then echo "Missing required variable ANDROID_KEY_PASSWORD"; exit 1; fi
- echo "storeFile=Cesium.keystore" > android/app/release-signing.properties
- echo "storePassword=${ANDROID_STORE_PASSWORD}" >> android/app/release-signing.properties
- echo "keyAlias=${ANDROID_KEY_ALIAS}" >> android/app/release-signing.properties
- echo "keyPassword=${ANDROID_KEY_PASSWORD}" >> android/app/release-signing.properties
# Show version
- npm version
- export NODE_OPTIONS=--max-old-space-size=4096
.configure-electron-template: &electron-setup
image: ${CI_BUILD_ELECTRON_IMAGE}
tags: [ kepler ]
before_script:
- if [[ -n ${APP_VERSION} ]]; then git fetch origin ; git checkout ${APP_VERSION} ; fi
- npm install
- npm run electron:install
- npm version
.configure-webext-template: &webext-setup
image: ${CI_BUILD_IMAGE}
tags: [ kepler ]
before_script:
- if [[ -n ${APP_VERSION} ]]; then git fetch origin ; git checkout ${APP_VERSION} ; fi
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
- npm install web-ext
- npm version
# ---------------------------------------------------------------
# Environment jobs : Create docker image for builds/release, this
# offers possibility to cache project dependencies so we don't
# have to download them every time.
# ---------------------------------------------------------------
build:env:
extends: .docker
stage: environment
script:
# Build and push the CI image
- docker build --cache-from ${CI_BUILD_IMAGE} -t ${CI_BUILD_IMAGE} --build-arg="BUILDKIT_INLINE_CACHE=1" --build-arg="CACHE_DIR=${BUILD_CACHE_DIR}" --build-arg="IMAGE_REGISTRY=${DOCKER_IMAGE_REGISTRY}" --build-arg="IONIC_CLI_VERSION=${IONIC_CLI_VERSION}" --build-arg="ANGULAR_CLI_VERSION=${ANGULAR_CLI_VERSION}" -f docker/build/Dockerfile .
- docker push ${CI_BUILD_IMAGE}
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- .gitlab-ci.yml
- docker/build/Dockerfile
- scripts/**/*
- package.json
- package-lock.json
# ---------------------------------------------------------------
# Build jobs
# ---------------------------------------------------------------
.build:
stage: build
tags: [ kepler ]
before_script:
# Get project dependencies
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
# Show version
- npm version
script:
# Build
- npm run build:${BUILD_ENVIRONMENT}
after_script:
# Remember version
- APP_VERSION=$(node -e "console.log(require('./package.json').version)")
- echo "APP_VERSION=${APP_VERSION}" > ${ENV_FILE}
artifacts:
paths:
- www
reports:
dotenv: ${ENV_FILE}
expire_in: 72 hours
build:
extends: .build
image: ${CI_BUILD_IMAGE}
only:
- develop
build:feature:
extends: .build
image: ${CI_BUILD_IMAGE}
script:
# Install deps, because it may have changed since the last build image (build from develop)
- npm install
# Build
- npm run build:${BUILD_ENVIRONMENT}
only:
- /^feature\/.*/
- /^features\/.*/
when: manual
# ---------------------------------------------------------------
# Package jobs
# ---------------------------------------------------------------
.package:android:
<<: *android-setup
stage: package
script:
# Build APK
- echo "--- Building Android APK ..."
- npm run android:build:${BUILD_ENVIRONMENT}
- npm run android:package:${BUILD_ENVIRONMENT}
after_script:
# Make APK file available for next jobs
- mkdir -p "${CI_PROJECT_DIR}/release/"
- mv -f ${CI_PROJECT_DIR}/android/app/build/outputs/apk/*/*.apk $CI_PROJECT_DIR/release/
artifacts:
paths:
- release
reports:
dotenv: ${ENV_FILE}
expire_in: 72 hours
when: manual
package:android:
extends: .package:android
needs: [ build ]
only:
- develop
package:android:feature:
extends: .package:android
needs: [ build:feature ]
only:
- /^feature\/.*/
- /^features\/.*/
.package:electron:
<<: *electron-setup
stage: package
script:
- echo "--- Building Electron packages ..."
- npm run electron:build:${BUILD_ENVIRONMENT}
- npm run electron:package:${BUILD_ENVIRONMENT}
after_script:
- mkdir -p "${CI_PROJECT_DIR}/release/"
- mv -f ${CI_PROJECT_DIR}/electron/dist/*.{AppImage,deb,exe} $CI_PROJECT_DIR/release/
artifacts:
paths:
- release
expire_in: 72 hours
when: manual
package:electron:
extends: .package:electron
needs: [ build ]
only:
- develop
package:electron:feature:
extends: .package:electron
needs: [ build:feature ]
only:
- /^feature\/.*/
- /^features\/.*/
.package:webext:
<<: *webext-setup
image: ${CI_BUILD_IMAGE}
stage: package
script:
- echo "--- Building webext package ..."
- npm run webext:build:${BUILD_ENVIRONMENT}
- npm run webext:package:${BUILD_ENVIRONMENT}
artifacts:
paths:
- release
when: manual
package:webext:
extends: .package:webext
needs: [ build ]
only:
- develop
package:webext:feature:
extends: .package:webext
needs: [ build:feature ]
only:
- /^feature\/.*/
- /^features\/.*/
# ---------------------------------------------------------------
# Release jobs
# ---------------------------------------------------------------
.release:
<<: *git-setup
stage: release
script:
- if [[ "_${RELEASE_VERSION}" == "_" ]]; then echo "Missing required variable RELEASE_VERSION"; exit 1; fi
# Copy cached dependencies and build
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
- echo "--- Release in progress"
- git checkout -B release/${RELEASE_VERSION}
- echo "--- Manage app version"
- npm run version:get
- npm run version:set ${RELEASE_VERSION}
# Git process for release (ISO gitflow)
- echo "--- Fishing release"
- git add .
- git status
- git commit -m "Prepare release ${RELEASE_VERSION}" --no-verify
- if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then git checkout master; fi
- if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then git reset --hard origin/master ; fi
- if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then git merge --no-ff --no-edit -m "Release ${RELEASE_VERSION}" "release/${RELEASE_VERSION}" ; fi
- git tag -f -a "${RELEASE_VERSION}" -m "${RELEASE_VERSION}"
- git checkout ${CI_COMMIT_REF_NAME}
- git reset --hard origin/${CI_COMMIT_REF_NAME}
- git merge --no-ff --no-edit -m "[skip ci] Release ${RELEASE_VERSION}" "release/${RELEASE_VERSION}"
- git push origin ${CI_COMMIT_REF_NAME}
- if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then git push origin master ; fi
- git push origin refs/tags/${RELEASE_VERSION}
- git branch -D "release/${RELEASE_VERSION}"
after_script:
- if [[ "_${RELEASE_VERSION}" == "_" ]]; then echo "Missing required variable RELEASE_VERSION"; exit 1; fi
# Remember version
- APP_VERSION=${RELEASE_VERSION}
- echo "APP_VERSION=${APP_VERSION}" > ${ENV_FILE}
- mkdir -p ${CI_PROJECT_DIR}/release
artifacts:
paths:
- release
reports:
dotenv: ${ENV_FILE}
expire_in: 24 hours
allow_failure: false
when: manual
release:
extends: .release
image: ${CI_BUILD_IMAGE}
needs: [build]
only:
- develop
release:feature:
extends: .release
image: ${CI_BUILD_IMAGE}
needs: [build:feature]
only:
- /^feature\/.*/
- /^features\/.*/
when: manual
gitlab-release:
stage: release
tags: [ kepler ]
image: ${CI_BUILD_IMAGE}
script:
- echo "running release for ${CI_COMMIT_TAG}"
- '[ -d "${BUILD_CACHE_DIR}" ] || mkdir "${BUILD_CACHE_DIR}"'
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
- npm install
- npm run release:create --token=${CI_JOB_TOKEN} "Release ${CI_PROJECT_NAME}-${CI_COMMIT_TAG}" "${CI_COMMIT_TAG}" "${CI_COMMIT_TAG}"
only:
- tags
# ---------------------------------------------------------------
# Deploy jobs
# ---------------------------------------------------------------
.deploy:web:
stage: deploy
needs: [release]
image: ${CI_BUILD_IMAGE}
script:
- if [[ -n ${APP_VERSION} ]]; then git fetch origin ; git checkout ${APP_VERSION} ; fi
# Copy cached dependencies and build
- ls -artl "${BUILD_CACHE_DIR}"
- ln -s "${BUILD_CACHE_DIR}/node_modules" node_modules
# Show version
- npm version
# Build web (if need)
- echo "--- Building 'www'"
- export NODE_OPTIONS=--max-old-space-size=4096
- npm run build:prod
- fileName=${CI_PROJECT_NAME}-${APP_VERSION}-web.zip
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- if [[ -f "${releaseFile}" ]]; then rm "${releaseFile}"; fi
- cd ${CI_PROJECT_DIR}/www || exit 1
- if ! zip -q -r "${releaseFile}" . ; then echo "Cannot create the archive for the web artifact"; exit 1; fi
- cd ${CI_PROJECT_DIR}
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
artifacts:
paths:
- release
reports:
dotenv: ${ENV_FILE}
expire_in: 24 hours
deploy:web:
extends: .deploy:web
needs: [release]
only:
- develop
deploy:web:feature:
extends: .deploy:web
needs: [release:feature]
only:
- /^feature\/.*/
- /^features\/.*/
when: manual
deploy:web:tags:
extends: .deploy:web
needs: [gitlab-release]
only:
- tags
when: manual
.deploy:android:
<<: *android-setup
stage: deploy
needs: [release]
script:
- sourceFile="${CI_PROJECT_DIR}/android/app/build/outputs/apk/release/app-release.apk"
# Build APK (if not already done)
- echo "--- Building Android package ..."
- npm run android:build:prod
- npm run android:package:prod
# Deploy as a release package
- fileName=${CI_PROJECT_NAME}-${APP_VERSION}-android.apk
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- if [[ -f "${releaseFile}" ]]; then rm "${releaseFile}"; fi
- mv "${sourceFile}" "${releaseFile}"
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
artifacts:
paths:
- release
expire_in: 24 hours
allow_failure: true
deploy:android:
extends: .deploy:android
needs: [release]
only:
- develop
deploy:android:feature:
extends: .deploy:android
needs: [release:feature]
only:
- /^feature\/.*/
- /^features\/.*/
when: manual
deploy:android:tags:
extends: .deploy:android
needs: [gitlab-release]
only:
- tags
when: manual
.deploy:electron:
<<: *electron-setup
stage: deploy
script:
- echo "--- Building Electron linux package ..."
- npm version
- npm run electron:build:prod
- npm run electron:package:prod
after_script:
- mkdir -p "${CI_PROJECT_DIR}/release/"
- mv -f ${CI_PROJECT_DIR}/electron/dist/*.{AppImage,deb,exe} $CI_PROJECT_DIR/release/
- ls -l "${CI_PROJECT_DIR}/release/"
# Deploy Linux Debian
- fileName=${CI_PROJECT_NAME}-${APP_VERSION}-linux-amd64.deb
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
# Deploy Linux AppImage
- fileName=${CI_PROJECT_NAME}-${APP_VERSION}-linux-x86_64.AppImage
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
# Deploy Windows exe
- fileName=${CI_PROJECT_NAME}-${APP_VERSION}-windows-x64.exe
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
artifacts:
paths:
- release
expire_in: 24 hours
allow_failure: false
deploy:electron:
extends: .deploy:electron
needs: [release]
only:
- develop
deploy:electron:feature:
extends: .deploy:electron
needs: [release:feature]
only:
- /^feature\/.*/
- /^features\/.*/
when: manual
deploy:electron:tags:
extends: .deploy:electron
needs: [gitlab-release]
only:
- tags
when: manual
.deploy:webext:
<<: *webext-setup
stage: deploy
script:
- npm version
- npm run webext:build:prod
- npm run webext:package:prod
- npm run webext:deploy:${DEPLOY_ENVIRONMENT}
after_script:
- ls -artl "${CI_PROJECT_DIR}/release"
- fileName=$(basename $(echo release/cesium-*.xpi))
- releaseFile=${CI_PROJECT_DIR}/release/${fileName}
- npm run release:upload_file --token=${CI_JOB_TOKEN} "${CI_PROJECT_NAME}" "${APP_VERSION}" "${releaseFile}" "link_release"
artifacts:
paths:
- release
expire_in: 24 hours
allow_failure: false
when: manual
deploy:webext:prerelease:
extends: .deploy:webext
needs: [release]
variables:
DEPLOY_ENVIRONMENT: 'test'
only:
- develop
deploy:webext:prerelease:feature:
extends: .deploy:webext
needs: [release:feature]
variables:
DEPLOY_ENVIRONMENT: 'test'
only:
- /^feature\/.*/
- /^features\/.*/
deploy:webext:prerelease:tags:
extends: .deploy:webext
needs: [gitlab-release]
variables:
DEPLOY_ENVIRONMENT: 'test'
only:
- tags
deploy:webext:release:
extends: .deploy:webext
needs: [release]
variables:
DEPLOY_ENVIRONMENT: 'prod'
only:
- develop
deploy:webext:release:feature:
extends: .deploy:webext
needs: [release:feature]
variables:
DEPLOY_ENVIRONMENT: 'prod'
only:
- /^feature\/.*/
- /^features\/.*/
deploy:webext:release:tags:
extends: .deploy:webext
needs: [gitlab-release]
variables:
DEPLOY_ENVIRONMENT: 'prod'
only:
- tags