-
Notifications
You must be signed in to change notification settings - Fork 307
/
.gitlab-ci.yml
384 lines (351 loc) · 10.3 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
default:
image: ${PROTON_CI_REGISTRY}/android-shared/docker-android/oci-ndk:v2.1.6
tags:
- shared-small
before_script:
# We must keep these variables here. We can't do it inside the entrypoint, as idk how but
# gitlab is going to convert them as a variable content instead of a variable file...
- mkdir -p app
- base64 -d - < "$SERVICE_ACCOUNT_FILE" > app/service_account.json
- md5sum app/service_account.json
- echo "" >> gradle.properties # ensure a new line
- base64 -d - < "$GRADLE_PROPERTIES_FILE2" >> gradle.properties
- git fetch origin development
- if [[ -f /load-env.sh ]]; then source /load-env.sh; fi
- if [ "$CI_JOB_STAGE" == "build" ] || [ "$CI_JOB_STAGE" == "publish" ]; then python3 $CI_PREPARE_TEST_ASSETS_PY; fi
interruptible: true
variables:
ATLAS_DEPLOY_SCOPE: $CI_PIPELINE_IID
ATLAS_DEPLOY_LIST:
value: fe-vpn:branch-main
description: List of components to deploy (fe-vpn:v4.7.0:prod+t to use a tag)
GIT_FETCH_EXTRA_FLAGS: --tags
ORG_GRADLE_PROJECT_useCoreGitSubmodule: "false"
NEXUS_GROUP: "/Vpn/Android/SLI/Latest/Stable"
NEXUS_REPO: "test-productivity-builds-distribution"
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule"' # Run scheduled pipelines without deploying atlas for tests.
- if: '"true" == "true"' # Run all other pipelines with test env deployed to atlas.
variables:
ATLAS_DEPLOY_ENV: "true"
ATLAS_DEPLOY_PREP: "true"
stages:
- prepare
- build
- sign
- startReview
- deploy
- test
- report
- bot
- mirror
- publish
- cleanup
# Make development and master uninterruptible.
# Based on https://gitlab.com/gitlab-org/gitlab/-/issues/194023#note_928958193
prevent-interrupt:
stage: .pre
rules:
- if: $CI_COMMIT_BRANCH == "development" || $CI_COMMIT_BRANCH == "master"
when: always
interruptible: false
cache: []
before_script: []
variables:
GIT_STRATEGY: none
script:
- echo "$CI_COMMIT_BRANCH is uninterruptible"
.gradle-build-cache: &gradle-build-cache
key:
prefix: gradle-build-cache
files:
- gradle/wrapper/gradle-wrapper.properties
paths:
- ${CI_PROJECT_DIR}/build/gradle-build-cache
policy: pull
cache:
- key: $CI_COMMIT_REF_SLUG
policy: pull
paths:
- .gradle
- <<: *gradle-build-cache
deploy:review:
needs:
- claim:review
after_script:
- sleep 10
- !reference [ .deploy:review, after_script ]
- 'curl -s -o /dev/null --show-error -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "_method=put&mockConfig=GET+%2Fcore%2Fv4%2Fnotifications%3A%0D%0A++-+type%3A+json%0D%0A++++body%3A%0D%0A++++++Notifications%3A+%5B%5D%0D%0A" "https://${DYNAMIC_DOMAIN}/api/internal/mock"'
detekt analysis:
stage: prepare
cache:
- key: $CI_COMMIT_REF_SLUG
policy: pull-push
paths:
- .gradle
except:
- schedules
tags:
- shared-large
script:
- ./gradlew :app:detekt
artifacts:
expire_in: 4 weeks
paths:
- app/build/reports/detekt/
reports:
codequality: app/build/reports/detekt/detekt.json
# Any jobs which needs ARCHIVES_BASE_NAME should add this job as dependency
# Unless the job is building the app from gradle, then it will be calculated on it's own
export archive name:
stage: prepare
tags:
- shared-medium
script:
- export ARCHIVES_BASE_NAME=$(./gradlew -q getArchivesName | tail -n 1)
- echo ${ARCHIVES_BASE_NAME}
- echo "ARCHIVES_BASE_NAME=${ARCHIVES_BASE_NAME}" >> deploy.env
- export VERSION_NAME=$(./gradlew -q getVersionName | tail -n 1)
- echo ${VERSION_NAME}
- echo "VERSION_NAME=${VERSION_NAME}" >> deploy.env
- export VERSION_CODE=$(./gradlew -q getVersionCode | tail -n 1)
- if [ $? -ne 0 ] || [ -z "${VERSION_CODE}" ]; then echo "VERSION_CODE is empty, something went wrong"; exit 1; fi
- echo ${VERSION_CODE}
- echo "VERSION_CODE=${VERSION_CODE}" >> deploy.env
artifacts:
reports:
dotenv: deploy.env
build google debug:
stage: build
rules:
- if: $ROBO_TEST == "true"
when: always
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- when: always
tags:
- xlarge-k8s
script:
# Build additionally the vanilla and Amazon flavors to check that they compile.
# Don't include them in artifacts.
- >
./gradlew assembleProductionGooglePlayStoreDebug \
assembleProductionVanillaOpenSourceDebug \
assembleProductionVanillaAmazonDebug \
assembleProductionGooglePlayStoreDebugAndroidTest
artifacts:
expire_in: 1 week
paths:
- app/build/outputs/apk/productionGooglePlayStore
- app/build/outputs/apk/androidTest/productionGooglePlayStore
.build test:
stage: build
tags:
- xlarge-k8s
except:
- schedules
script:
- export BLACK_TOKEN="$(curl --silent $BLACK_TOKEN_URL)"
- echo "API host ${TEST_ENV_DOMAIN}"
- echo "API token ${BLACK_TOKEN}"
- |
if [[ "$BLACK_TOKEN" == *$'\n'* || "$BLACK_TOKEN" == *" "* ]]; then
echo "Invalid token: ${BLACK_TOKEN}"
exit 1
fi
- mkdir -p app/src/androidTest/assets/sensitive
- cat $TEST_INTERNAL_API > app/src/androidTest/assets/sensitive/internal_apis.json
- >
./gradlew assembleBlackGooglePlayStoreDebug \
assembleBlackGooglePlayStoreDebugAndroidTest
artifacts:
expire_in: 1 week
paths:
- app/build/outputs/apk
- app/build/tmp/kotlin-classes
build test-env:
variables:
TEST_ENV_DOMAIN: $DYNAMIC_DOMAIN
extends: .build test
build black:
extends: .build test
variables:
TEST_ENV_DOMAIN: $BLACK_DOMAIN
after_script:
# Avoid build files clashing with the test ones.
- mkdir artifactsBlack
- mv app/build/outputs/apk/* artifactsBlack
when: manual
artifacts:
expire_in: 1 week
paths:
- artifactsBlack
build BTI:
stage: build
when: manual
except:
- schedules
tags:
- xlarge-k8s
script:
- ./gradlew assembleBlackGooglePlayStoreDebug
after_script:
# Avoid build files clashing with the test ones.
- mkdir artifactsBti
- mv app/build/outputs/apk/* artifactsBti
artifacts:
expire_in: 3 week
paths:
- artifactsBti
build google play release:
stage: build
when: manual
tags:
- xlarge-k8s
script:
- >
./gradlew openvpn:assembleRelease \
assembleProductionGooglePlayStoreRelease
except:
- schedules
interruptible: false
artifacts:
expire_in: 1 week
paths:
- app/build/outputs/apk
build google play dev (monitoring release):
stage: build
rules:
- if: $ROBO_TEST == "true"
when: always
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- when: always
tags:
- xlarge-k8s
script:
- >
./gradlew openvpn:assembleRelease \
assembleProductionGoogleDevRelease \
:release_tests:assembleRelease
interruptible: false
artifacts:
expire_in: 1 week
paths:
- app/build/outputs/apk
- release_tests/build/outputs/apk
unit tests:
stage: test
tags:
- xlarge-k8s
except:
- schedules
script:
- ./gradlew testBlackGooglePlayStoreDebug
artifacts:
expire_in: 1 day
paths:
- app/build/test-results
- app/build/outputs/unit_test_code_coverage
- app/build/reports/tests
coverage report:
stage: report
tags:
- shared-large
script:
- ./gradlew coverageReport
- python3 jacocoConverter.py app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml app/src/main/java > app/build/reports/cobertura-coverage.xml
# create top level artifact index to direct users to the deep index
- echo "<script>window.location='app/build/reports/jacoco/jacocoTestReport/html/index.html'</script>" > index.html
- echo "<a href='app/build/reports/jacoco/jacocoTestReport/html/index.html'>go here</a>" >> index.html
only:
- branches
except:
- schedules
allow_failure: true
coverage: '/Total coverage: \d+.\d+/'
artifacts:
expire_in: 1 week
expose_as: 'Coverage html'
paths:
- app/build/reports/jacoco/jacocoTestReport/html
- index.html
reports:
coverage_report:
coverage_format: cobertura
path: app/build/reports/cobertura-coverage.xml
pages:
stage: publish
only:
refs:
- development
except:
- schedules
script:
- mkdir public
- mv app/build/reports/jacoco/jacocoTestReport/html/* public
artifacts:
paths:
- public
owasp check:
stage: prepare
tags:
- shared-large
script:
- ./gradlew dependencyCheckAggregate
when: manual
interruptible: false
artifacts:
expire_in: 1 week
paths:
- build/reports
startReview:
before_script:
- export REVIEW_APP_ARTIFACT_PATH="app/build/outputs/apk/productionGooglePlayStore/debug/"${ARCHIVES_BASE_NAME}-production-google-playStore-debug.apk
- echo ${REVIEW_APP_ARTIFACT_PATH}
extends: .startReview
needs: ["build google debug", "export archive name"]
except:
- schedules
stopReview:
before_script: []
extends: .stopReview
include:
- project: 'translations/generator'
ref: master
file: '/jobs/sync-crowdin.gitlab-ci.yml'
- component: gitlab.protontech.ch/proton/devops/cicd-components/devsecops/gitleaks/[email protected]
inputs:
stage: prepare
- project: 'translations/generator'
ref: master
file: '/jobs/commit-locales.gitlab-ci.yml'
- project: 'proton/mobile/android/proton-libs'
ref: main
file: '/ci/templates-shared/appetize-integration.yml'
- local: '/.gitlab-ci-firebase.yml'
- local: '/.gitlab-ci-release.yml'
- project: 'proton/devops/atlas-deploy'
ref: main
file: '/scenarios/pipeline-env.yml'
- project: 'proton/devops/tooling/templates'
ref: main
file: '/packaging/signing/artifact-signing.gitlab-ci.yml'
i18n-sync-crowdin:
variables:
I18N_SYNC_BRANCH: development
I18N_SYNC_CROWDIN_PROJECT: 'android-vpn'
extends: .i18n-sync-crowdin-shared
i18n-commit-locales:
variables:
I18N_COMMIT_BRANCH_PUSH: development
I18N_COMMIT_BRANCH_ALLOWED: development
I18N_COMMIT_CROWDIN_PROJECT: 'android-vpn'
extends: .i18n-commit-locales-shared