-
-
Notifications
You must be signed in to change notification settings - Fork 51
328 lines (293 loc) · 13.3 KB
/
integration_tests_app_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
# Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
# Licensed under the EUPL-1.2-or-later.
#
# You may obtain a copy of the Licence at:
# https://joinup.ec.europa.eu/software/page/eupl
#
# SPDX-License-Identifier: EUPL-1.2
# This workflow is used to run integration tests on the app.
#
# We only run the integration tests in our merge group to save macOS machines.
name: integration-tests-app-ci
on:
pull_request:
paths:
# We trigger also this workflow, if this workflow is changed, so that new
# changes can be tested.
- ".github/workflows/integration_tests_app_ci.yml"
merge_group:
types:
- checks_requested
# Set permissions to none.
#
# Using the broad default permissions is considered a bad security practice
# and would cause alerts from our scanning tools.
permissions: {}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# We can't use the official "paths" filter because it has no support for merge
# groups and we would need some kind of fallback CI when a check is required
# but ignored because of the path filter.
#
# See:
# * https://github.com/community/community/discussions/45899 (merge groups)
# * https://github.com/github/docs/commit/4364076e0fb56c2579ae90cd048939eaa2c18954
# (workaround for required checks with path filters)
changes:
runs-on: ubuntu-22.04
outputs:
changesFound: ${{ steps.filter.outputs.changesFound }}
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: AurorNZ/paths-filter@3b1f3abc3371cca888d8eb03dfa70bc8a9867629
id: filter
with:
filters: |
changesFound:
# When we change the Flutter version, we need to trigger this workflow.
- ".fvm/fvm_config.json"
# We only build and deploy a new version, when user relevant files
# or integration test files changed.
- "app/**"
- "lib/**"
- "app/integration_test/**"
# We trigger also this workflow, if this workflow is changed, so that new
# changes will be applied.
- ".github/workflows/integration_tests_app_ci.yml"
# The following paths are excluded from the above paths. It's important to
# list the paths at the end of the file, so that the exclude paths are
# applied.
#
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths.
- "!**/*.md"
- "!**/*.mdx"
- "!**/*.gitignore"
- "!**/firebase.json"
- "!**/.firebaserc"
- "!app/android/fastlane/**"
android-integration-test:
needs: changes
runs-on: ubuntu-22.04
if: ${{ needs.changes.outputs.changesFound == 'true' }}
# Don't use less than 90 minutes. Often 40 minutes are enough but sometimes
# (~5% of the time) build takes longer and then is a long timeout needed.
defaults:
run:
working-directory: app
timeout-minutes: 90
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
# Our Android configurations require Java 17.
- uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73
with:
distribution: "oracle"
java-version: "17"
- name: Set Flutter version from FVM config file to environment variables
id: fvm-config-action
uses: kuhnroyal/flutter-fvm-config-action@60c14af316b09f8819202d845391260cf3b979c9
- uses: subosito/flutter-action@main
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
- name: Install patrol cli
run: flutter pub global activate patrol_cli 3.2.0
- name: Run Flutter build
run: |
# Flutter build is required to generate files in android/ to build the
# gradle project.
#
# We are using the prod flavor because we were not able to set up
# Firebase Test Lab with the dev flavor. We always got "No tests
# found.".
flutter build apk \
--target=lib/main_prod.dart \
--flavor prod \
--config-only
- name: Build Instrumentation Test
run: |
patrol build android \
--flavor prod \
--dart-define USER_1_EMAIL=${{ secrets.INTEGRATION_TEST_USER_1_EMAIL }} \
--dart-define USER_1_PASSWORD=${{ secrets.INTEGRATION_TEST_USER_1_PASSWORD }} \
-t integration_test/app_test.dart
- name: Setup credentials
env:
TEST_LAB_CREDENTIALS: ${{ secrets.FIREBASE_TEST_LAB_DEV_KEY }}
run: |
echo $TEST_LAB_CREDENTIALS > firebase-test-lab.json
gcloud auth activate-service-account --key-file=firebase-test-lab.json
gcloud --quiet config set project sharezone-debug
# Runs our integration tests with Firebase Test Lab.
#
# Advantages of Firebase Test Lab:
# * We can use a Linux runner instead of a macOS runner in
# Github Actions (macOS runner is required for using an Android emulator).
# * We can run the tests on a real device instead of an emulator.
# * We get a screen recording of the test run which we can use to
# investigate test failures.
# * Increases the speed of the CI by 10 minutes (compared to running the
# tests on a macOS runner).
#
# Helpful documentation:
# * https://firebase.google.com/docs/test-lab/android/command-line
- name: Run Integration tests
run: |
gcloud firebase test android run \
--type instrumentation \
--app build/app/outputs/apk/prod/debug/app-prod-debug.apk \
--test build/app/outputs/apk/androidTest/prod/debug/app-prod-debug-androidTest.apk \
--device model=Pixel2,version=30,locale=en,orientation=portrait \
--timeout 10m \
--use-orchestrator \
--environment-variables clearPackageData=true
# It can easily happen that a dependency changed but the .lock file is not
# updated. Or other cases where files are changed during a build.
# Therefore, fails this check if there are Git changes.
- name: Fail if there are Git diffs
run: |
# Fail if there are Git diffs and print the diff.
git diff --exit-code
# Print the Git diff with the file names and their status as a
# summary.
git diff --name-status
ios-integration-test:
needs: changes
runs-on: macos-15
if: ${{ needs.changes.outputs.changesFound == 'true' }}
timeout-minutes: 60
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- name: Set Flutter version from FVM config file to environment variables
id: fvm-config-action
uses: kuhnroyal/flutter-fvm-config-action@60c14af316b09f8819202d845391260cf3b979c9
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
- uses: futureware-tech/simulator-action@48e51da14445b3eedca643bba4b78d9d8332ff31
id: simulator
with:
model: "iPhone 16"
- name: Build app
working-directory: app
run: |
flutter build ipa \
--flavor dev \
-t lib/main_dev.dart \
--no-codesign
- name: Run integration tests
working-directory: app
env:
USER_1_EMAIL: ${{ secrets.INTEGRATION_TEST_USER_1_EMAIL }}
USER_1_PASSWORD: ${{ secrets.INTEGRATION_TEST_USER_1_PASSWORD }}
SIMULATOR_UDID: ${{ steps.simulator.outputs.udid }}
# We use the `flutter drive` instead of the `flutter test` command
# because the test command times out after 12 minutes. But building the
# app takes more than 12 minutes... It seems so that there is no way to
# set the timeout (the --timeout argument has not effect). Tracking
# issue: https://github.com/flutter/flutter/issues/105913
run: |
# We need to run the integration tests with the prod flavor because
# using not the default flavor will cause an exception when
# uninstalling the app, see:
# https://github.com/flutter/flutter/issues/88690
flutter test integration_test/integration_test_old.dart \
--flavor prod \
--dart-define=USER_1_EMAIL=$USER_1_EMAIL \
--dart-define=USER_1_PASSWORD=$USER_1_PASSWORD \
-d $SIMULATOR_UDID
web-integration-test:
needs: changes
runs-on: ubuntu-22.04
if: ${{ needs.changes.outputs.changesFound == 'true' }}
timeout-minutes: 30
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- name: Set Flutter version from FVM config file to environment variables
id: fvm-config-action
uses: kuhnroyal/flutter-fvm-config-action@60c14af316b09f8819202d845391260cf3b979c9
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
- name: Install chromedriver
uses: nanasess/setup-chromedriver@42cc2998329f041de87dc3cfa33a930eacd57eaa
- name: Run integration tests
working-directory: app
env:
USER_1_EMAIL: ${{ secrets.INTEGRATION_TEST_USER_1_EMAIL }}
USER_1_PASSWORD: ${{ secrets.INTEGRATION_TEST_USER_1_PASSWORD }}
# We use the `flutter drive` command because `flutter test` is not
# available for the web yet.
run: |
chromedriver --port=4444 &
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/integration_test_old.dart \
--flavor dev \
--dart-define=USER_1_EMAIL=$USER_1_EMAIL \
--dart-define=USER_1_PASSWORD=$USER_1_PASSWORD \
-d web-server
# At the moment, Flutter Integration Tests are not working with GitHub Actions
# and Flutter +3.7 (see https://github.com/flutter/flutter/issues/118469).
#
# To still have a verification that the app can be built, we just build the
# macOS app.
macos-build-test:
needs: changes
runs-on: macos-14
if: ${{ needs.changes.outputs.changesFound == 'true' }}
timeout-minutes: 60
defaults:
run:
working-directory: app
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: "3.9"
- name: Install Codemagic CLI Tools
run: pip3 install codemagic-cli-tools==0.50.7
- name: Setup signing
env:
# The following secrets are used by the Codemagic CLI tool. It's important
# to use the same names as the CLI tool expects.
CERTIFICATE_PRIVATE_KEY: ${{ secrets.SHAREZONE_CERTIFICATE_PRIVATE_KEY }}
APP_STORE_CONNECT_KEY_IDENTIFIER: ${{ secrets.SHAREZONE_APP_STORE_CONNECT_KEY_IDENTIFIER }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.SHAREZONE_APP_STORE_CONNECT_ISSUER_ID }}
APP_STORE_CONNECT_PRIVATE_KEY: ${{ secrets.SHAREZONE_APP_STORE_CONNECT_PRIVATE_KEY }}
BUNDLE_ID: de.codingbrain.sharezone.app.dev
run: |
# Even when are trying to build app, we need to use "--platform IOS".
# The reason for this that our production bundle ID was created for
# IOS only. However, it's still possible to sign a macOS app with an
# iOS bundle ID (requires "--strict-match-identifier", otherwise the
# tool would try to use our de.codingbrain.sharezone.app.dev bundle ID
# which is a universal bundle ID and has no specific platform).
#
# See https://github.com/codemagic-ci-cd/cli-tools/issues/314
app-store-connect fetch-signing-files $BUNDLE_ID \
--platform IOS \
--type MAC_APP_STORE \
--strict-match-identifier \
--create
keychain initialize
keychain add-certificates
xcode-project use-profiles
- name: Set Flutter version from FVM config file to environment variables
id: fvm-config-action
uses: kuhnroyal/flutter-fvm-config-action@60c14af316b09f8819202d845391260cf3b979c9
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
# We need to install the FlutterFire CLI because we have Build Phases in
# XCode configured which are using the FlutterFire CLI. Without the CLI,
# the build would fail.
- name: Install FlutterFire CLI
run: flutter pub global activate flutterfire_cli 0.3.0-dev.19
- name: Build macOS app
run: |
flutter build macos \
--flavor dev \
-t lib/main_dev.dart