-
Notifications
You must be signed in to change notification settings - Fork 113
407 lines (369 loc) · 14.5 KB
/
reusable-release-pipeline.yml
File metadata and controls
407 lines (369 loc) · 14.5 KB
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
name: Reusable Release Pipeline
on:
workflow_call:
inputs:
app-name:
description: 'App name (student, teacher, parent)'
required: true
type: string
app-display-name:
description: 'App display name (Student, Teacher, Parent)'
required: true
type: string
include-e2e-offline:
description: 'Include E2E offline tests (Student only)'
required: false
default: false
type: boolean
slack-emoji:
description: 'Slack emoji for the app'
required: true
type: string
secrets:
GH_APP_ID:
required: true
GH_APP_PRIVATE_KEY:
required: true
ANDROID_RELEASE_KEYSTORE_B64:
required: true
GCLOUD_KEY:
required: true
SPLUNK_MOBILE_TOKEN:
required: true
OBSERVE_MOBILE_TOKEN:
required: true
ANDROID_KEYSTORE_PASSWORD:
required: true
ANDROID_KEYSTORE_ALIAS:
required: true
ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD:
required: true
SLACK_URL:
required: true
jobs:
build-qa-debug:
name: build-qa-debug
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: canvas-android,android-vault
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 1
token: ${{ steps.app-token.outputs.token }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
java-version: '17'
- name: Build QA debug and test APKs
run: |
./gradle/gradlew -p apps \
:${{ inputs.app-name }}:assembleQaDebug \
:${{ inputs.app-name }}:assembleQaDebugAndroidTest \
--build-cache \
--parallel \
--max-workers=4 \
--no-daemon \
-Dorg.gradle.jvmargs="-Xmx6g -XX:+HeapDumpOnOutOfMemoryError" \
-Dkotlin.compiler.execution.strategy=in-process
env:
GRADLE_OPTS: "-Djava.net.preferIPv4Stack=true"
- name: Upload QA debug APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-name }}-qa-debug.apk
path: apps/${{ inputs.app-name }}/build/outputs/apk/qa/debug/${{ inputs.app-name }}-qa-debug.apk
retention-days: 1
- name: Upload QA test APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-name }}-qa-debug-androidTest.apk
path: apps/${{ inputs.app-name }}/build/outputs/apk/androidTest/qa/debug/${{ inputs.app-name }}-qa-debug-androidTest.apk
retention-days: 1
unit-tests:
name: unit-tests
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: canvas-android,android-vault
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 1
token: ${{ steps.app-token.outputs.token }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
java-version: '17'
- name: Run unit tests
run: |
./gradle/gradlew -p apps \
:${{ inputs.app-name }}:testDevDebugUnitTest \
--build-cache \
--parallel \
--max-workers=4 \
--no-daemon \
-Dorg.gradle.jvmargs="-Xmx6g -XX:+HeapDumpOnOutOfMemoryError" \
-Dkotlin.compiler.execution.strategy=in-process
env:
GRADLE_OPTS: "-Djava.net.preferIPv4Stack=true"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-name }}-unit-test-results
path: |
apps/${{ inputs.app-name }}/build/reports/tests/testDevDebugUnitTest/
apps/${{ inputs.app-name }}/build/test-results/testDevDebugUnitTest/
retention-days: 1
flank-tests:
name: flank-${{ matrix.test-type }}
runs-on: ubuntu-latest
timeout-minutes: 60
needs: build-qa-debug
strategy:
fail-fast: false
matrix:
include:
- test-type: portrait
flank-config: flank_portrait_interaction_release.yml
- test-type: landscape
flank-config: flank_landscape_interaction_release.yml
- test-type: tablet
flank-config: flank_tablet_interaction_release.yml
- test-type: e2e
flank-config: flank_e2e_release.yml
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Setup Service account
env:
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
run: |
if [ -z "${GCLOUD_KEY}" ]; then
echo "Error: GCLOUD_KEY secret is not set"
exit 1
fi
echo "${GCLOUD_KEY}" > service-account-key.json
chmod 600 service-account-key.json
- name: Setup Flank config
run: cp ./apps/${{ inputs.app-name }}/release_tests/${{ matrix.flank-config }} ./flank.yml
- name: Copy APKs to expected locations
run: |
if [ -d "${{ inputs.app-name }}-qa-debug.apk" ]; then
mkdir -p apps/${{ inputs.app-name }}/build/outputs/apk/qa/debug
mv ${{ inputs.app-name }}-qa-debug.apk/${{ inputs.app-name }}-qa-debug.apk apps/${{ inputs.app-name }}/build/outputs/apk/qa/debug/
rm -rf ${{ inputs.app-name }}-qa-debug.apk
fi
if [ -d "${{ inputs.app-name }}-qa-debug-androidTest.apk" ]; then
mkdir -p apps/${{ inputs.app-name }}/build/outputs/apk/androidTest/qa/debug
mv ${{ inputs.app-name }}-qa-debug-androidTest.apk/${{ inputs.app-name }}-qa-debug-androidTest.apk apps/${{ inputs.app-name }}/build/outputs/apk/androidTest/qa/debug/
rm -rf ${{ inputs.app-name }}-qa-debug-androidTest.apk
fi
- name: Run Flank tests
uses: Flank/flank@v23.10.1
with:
version: 'v23.07.0'
platform: 'android'
service_account: './service-account-key.json'
flank_configuration_file: './flank.yml'
- name: Report test results
if: always()
run: |
if [ -d results ] && [ "$(ls results 2>/dev/null | wc -l)" -eq 1 ]; then
./apps/postProcessTestRun.bash ${{ inputs.app-name }} results/$(ls results)
else
echo "Warning: Expected exactly one results directory, found: $(ls results 2>/dev/null || echo 'none')"
fi
env:
SPLUNK_MOBILE_TOKEN: ${{ secrets.SPLUNK_MOBILE_TOKEN }}
OBSERVE_MOBILE_TOKEN: ${{ secrets.OBSERVE_MOBILE_TOKEN }}
BITRISE_TRIGGERED_WORKFLOW_ID: ${{ github.workflow }}
BITRISE_GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
BITRISE_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Cleanup sensitive files
if: always()
run: rm -f service-account-key.json
e2e-offline:
name: e2e-offline
runs-on: ubuntu-latest
timeout-minutes: 60
needs: build-qa-debug
if: ${{ inputs.include-e2e-offline }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Setup Service account
env:
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
run: |
if [ -z "${GCLOUD_KEY}" ]; then
echo "Error: GCLOUD_KEY secret is not set"
exit 1
fi
echo "${GCLOUD_KEY}" > service-account-key.json
chmod 600 service-account-key.json
- name: Setup Flank config
run: cp ./apps/${{ inputs.app-name }}/flank_e2e_offline.yml ./flank.yml
- name: Copy APKs to expected locations
run: |
if [ -d "${{ inputs.app-name }}-qa-debug.apk" ]; then
mkdir -p apps/${{ inputs.app-name }}/build/outputs/apk/qa/debug
mv ${{ inputs.app-name }}-qa-debug.apk/${{ inputs.app-name }}-qa-debug.apk apps/${{ inputs.app-name }}/build/outputs/apk/qa/debug/
rm -rf ${{ inputs.app-name }}-qa-debug.apk
fi
if [ -d "${{ inputs.app-name }}-qa-debug-androidTest.apk" ]; then
mkdir -p apps/${{ inputs.app-name }}/build/outputs/apk/androidTest/qa/debug
mv ${{ inputs.app-name }}-qa-debug-androidTest.apk/${{ inputs.app-name }}-qa-debug-androidTest.apk apps/${{ inputs.app-name }}/build/outputs/apk/androidTest/qa/debug/
rm -rf ${{ inputs.app-name }}-qa-debug-androidTest.apk
fi
- name: Run Flank E2E offline tests
uses: Flank/flank@v23.10.1
with:
version: 'v23.07.0'
platform: 'android'
service_account: './service-account-key.json'
flank_configuration_file: './flank.yml'
- name: Report test results
if: always()
run: |
if [ -d results ] && [ "$(ls results 2>/dev/null | wc -l)" -eq 1 ]; then
./apps/postProcessTestRun.bash ${{ inputs.app-name }} results/$(ls results)
else
echo "Warning: Expected exactly one results directory, found: $(ls results 2>/dev/null || echo 'none')"
fi
env:
SPLUNK_MOBILE_TOKEN: ${{ secrets.SPLUNK_MOBILE_TOKEN }}
OBSERVE_MOBILE_TOKEN: ${{ secrets.OBSERVE_MOBILE_TOKEN }}
BITRISE_TRIGGERED_WORKFLOW_ID: ${{ github.workflow }}
BITRISE_GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
BITRISE_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Cleanup sensitive files
if: always()
run: rm -f service-account-key.json
build-release-candidate:
name: build-release-candidate
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [unit-tests, flank-tests, e2e-offline]
if: |
always() &&
needs.unit-tests.result == 'success' &&
needs.flank-tests.result == 'success' &&
(needs.e2e-offline.result == 'success' || needs.e2e-offline.result == 'skipped')
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: canvas-android,android-vault
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 1
token: ${{ steps.app-token.outputs.token }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
java-version: '17'
- name: Decode release keystore
env:
KEYSTORE_B64: ${{ secrets.ANDROID_RELEASE_KEYSTORE_B64 }}
run: |
echo "$KEYSTORE_B64" | base64 --decode > release.jks
chmod 600 release.jks
- name: Build release candidate
run: |
./gradle/gradlew -p apps \
:${{ inputs.app-name }}:assembleProdRelease \
:${{ inputs.app-name }}:bundleProdRelease \
--stacktrace \
--build-cache \
--parallel \
--max-workers=4 \
--no-daemon \
-Dorg.gradle.jvmargs="-Xmx6g -XX:+HeapDumpOnOutOfMemoryError" \
-Dkotlin.compiler.execution.strategy=in-process \
-Pandroid.injected.signing.store.file=$(pwd)/release.jks \
-Pandroid.injected.signing.store.password="${KEYSTORE_PASSWORD}" \
-Pandroid.injected.signing.key.alias="${KEYSTORE_KEY_ALIAS}" \
-Pandroid.injected.signing.key.password="${KEYSTORE_KEY_PASSWORD}"
env:
GRADLE_OPTS: "-Djava.net.preferIPv4Stack=true"
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
KEYSTORE_KEY_ALIAS: ${{ secrets.ANDROID_KEYSTORE_ALIAS }}
KEYSTORE_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }}
- name: Upload release APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-name }}-prod-release.apk
path: apps/${{ inputs.app-name }}/build/outputs/apk/prod/release/${{ inputs.app-name }}-prod-release.apk
retention-days: 7
- name: Upload release AAB
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-name }}-prod-release.aab
path: apps/${{ inputs.app-name }}/build/outputs/bundle/prodRelease/${{ inputs.app-name }}-prod-release.aab
retention-days: 7
- name: Cleanup sensitive files
if: always()
run: rm -f release.jks
slack-notification:
name: slack-notification
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [build-release-candidate]
if: always()
steps:
- name: Notify Slack on success
if: needs.build-release-candidate.result == 'success'
uses: slackapi/slack-github-action@v2
with:
webhook: ${{ secrets.SLACK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": ":android: ${{ inputs.slack-emoji }} Android ${{ inputs.app-display-name }} RC Available :android:\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Download artifacts from GitHub Actions>"
}
- name: Notify Slack on failure
if: needs.build-release-candidate.result != 'success'
uses: slackapi/slack-github-action@v2
with:
webhook: ${{ secrets.SLACK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": ":x: ${{ inputs.slack-emoji }} Android ${{ inputs.app-display-name }} Release Pipeline Failed\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View failed run>"
}