-
Notifications
You must be signed in to change notification settings - Fork 12
388 lines (372 loc) · 13.2 KB
/
test-and-build.yaml
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
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Run tests and build
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-dart:
name: Run dart unit tests
timeout-minutes: 45
runs-on:
labels: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
name: Checkout code
- uses: actions/setup-java@v4
name: Setup java
with:
distribution: "temurin"
java-version: "17"
cache: "gradle"
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
name: Setup flutter
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- uses: bluefireteam/melos-action@6085791af7036f6366c9a4b9d55105c0ef9c6388
with:
melos-version: "6.0.0"
- name: "Run flutter test"
run: melos run test:dart
test-android:
name: Run Android native unit tests
timeout-minutes: 45
runs-on:
labels: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
cache: "gradle"
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- name: Setup melos
uses: bluefireteam/melos-action@6085791af7036f6366c9a4b9d55105c0ef9c6388
with:
melos-version: "6.0.0"
- name: "Run Android native unit tests"
run: melos run test:android
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
include-hidden-files: true
path: example/build
retention-days: 1
test-ios:
name: Run iOS native unit tests
timeout-minutes: 45
runs-on:
labels: macos-latest-xlarge
env:
working_directory: "example"
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- name: Setup melos
uses: bluefireteam/melos-action@6085791af7036f6366c9a4b9d55105c0ef9c6388
with:
melos-version: "6.0.0"
- name: Cache podfiles
uses: actions/cache@v4
with:
path: "**/Pods"
key: ${{ runner.os }}-pods-${{ hashFiles('**/*.podspec') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Select XCode 16.0
run: sudo xcode-select -s '/Applications/Xcode_16.app/Contents/Developer'
- name: Generate necessary files with flutter build
working-directory: ${{ env.working_directory }}
run: flutter build ios --config-only
- name: "Run iOS native unit tests"
run: DEVICE='iPhone 16 Pro' melos run test:ios
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
include-hidden-files: true
path: example/build
retention-days: 1
build-android:
name: Build Android
needs: [test-dart, test-android, test-ios]
if: contains(github.base_ref, 'main')
timeout-minutes: 45
runs-on:
labels: ubuntu-latest
env:
MAPS_API_KEY: ${{ secrets.ACTIONS_API_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
cache: "gradle"
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- name: Setup melos
uses: bluefireteam/melos-action@6085791af7036f6366c9a4b9d55105c0ef9c6388
with:
melos-version: "6.0.0"
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
- name: "Run build for Android"
run: melos run flutter-build-android
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
include-hidden-files: true
path: example/build
retention-days: 1
overwrite: true
build-ios:
name: Build iOS
needs: [test-dart, test-android, test-ios]
if: contains(github.base_ref, 'main')
timeout-minutes: 90
runs-on:
labels: macos-latest-xlarge
env:
MAPS_API_KEY: ${{ secrets.ACTIONS_API_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
architecture: x64
- name: Setup melos
uses: bluefireteam/melos-action@6085791af7036f6366c9a4b9d55105c0ef9c6388
with:
melos-version: "6.0.0"
- name: Cache podfiles
uses: actions/cache@v4
with:
path: "**/Pods"
key: ${{ runner.os }}-pods-${{ hashFiles('**/*.podspec') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
- name: Select XCode 16.0
run: sudo xcode-select -s '/Applications/Xcode_16.app/Contents/Developer'
- name: "Run build for iOS"
run: melos run flutter-build-ios
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
include-hidden-files: true
path: example/build
retention-days: 1
overwrite: true
integration-test-android:
name: Run Android Integration Tests
needs: [build-android]
if: contains(github.base_ref, 'main')
timeout-minutes: 90
runs-on:
labels: ubuntu-latest
env:
MAPS_API_KEY: ${{ secrets.ACTIONS_API_KEY }}
patrol_cli_version: "3.2.0"
working_directory: "example"
steps:
- name: Fail if workflow has no access to API key
if: ${{ env.MAPS_API_KEY == '' }}
run: |
echo "MAPS_API_KEY is not available or empty."
exit 1
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
cache: "gradle"
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: AVD Cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
- name: Cache pub global packages
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ env.patrol_cli_version }}
- name: Install patrol_cli
run: flutter pub global activate patrol_cli ${{ env.patrol_cli_version }}
- name: Run flutter pub get
run: flutter pub get
- name: Create and start emulator
run: |
echo "List installed packages"
$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --list_installed
echo "Installing system image"
echo "y" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "system-images;android-35;google_apis;x86_64"
echo "Creating AVD"
echo "no" | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n test_emulator -k "system-images;android-35;google_apis;x86_64" --force
echo "Starting emulator"
$ANDROID_SDK_ROOT/emulator/emulator -avd test_emulator -no-audio -no-boot-anim -no-window -no-snapshot &
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
- name: Generate gradlew file with flutter build
working-directory: ${{ env.working_directory }}
run: flutter build apk --config-only
- name: Run integration tests
working-directory: ${{ env.working_directory }}
run: patrol test --verbose
- name: Upload test report
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: android_integration_test_report
path: example/build/app/reports/androidTests/connected/
retention-days: 5
integration-test-ios:
name: Run iOS Integration Tests
needs: [build-ios]
if: contains(github.base_ref, 'main')
timeout-minutes: 90
runs-on:
labels: macos-latest-xlarge
env:
MAPS_API_KEY: ${{ secrets.ACTIONS_API_KEY }}
patrol_cli_version: "3.2.0"
working_directory: "example"
steps:
- name: Fail if workflow has no access to API key
if: ${{ env.MAPS_API_KEY == '' }}
run: |
echo "MAPS_API_KEY is not available or empty."
exit 1
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: "3.22.x"
channel: "stable"
cache: true
- name: Select XCode 16.0
run: sudo xcode-select -s '/Applications/Xcode_16.app/Contents/Developer'
- name: Start iOS simulator
run: |
SIMULATOR_NAME="iPhone 16 Pro"
# Find the UUID of the existing simulator by name
DEVICE_ID=$(xcrun simctl list devices | grep "$SIMULATOR_NAME (" | grep -Eo "\([A-F0-9-]+\)" | head -n 1 | tr -d "()")
if [ -z "$DEVICE_ID" ]; then
echo "Simulator $SIMULATOR_NAME not found."
exit 1
else
echo "Found existing simulator: $SIMULATOR_NAME ($DEVICE_ID)"
echo "Erasing the simulator to ensure a clean state..."
xcrun simctl erase "$DEVICE_ID"
fi
echo "Booting the simulator..."
xcrun simctl boot "$DEVICE_ID"
# Save DEVICE_ID for later use
echo "DEVICE_ID=$DEVICE_ID" >> $GITHUB_ENV
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: ${{ runner.os }}-build-artifact
- name: Cache podfiles
uses: actions/cache@v4
with:
path: "**/Pods"
key: ${{ runner.os }}-pods-${{ hashFiles('**/*.podspec') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Cache pub global packages
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ env.patrol_cli_version }}
- name: Install patrol_cli
run: flutter pub global activate patrol_cli ${{ env.patrol_cli_version }}
- name: Run flutter pub get
run: flutter pub get
- name: Make sure the simulator is booted
run: |
xcrun simctl bootstatus "$DEVICE_ID" || exit 1
- name: Run Integration tests
id: tests_step
working-directory: ${{ env.working_directory }}
run: |
patrol test --dart-define=MAPS_API_KEY="$MAPS_API_KEY" --verbose -d "$DEVICE_ID"
- name: Upload test report
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: ios_integration_test_report
path: example/build/ios_results_*.xcresult
retention-days: 5