-
Notifications
You must be signed in to change notification settings - Fork 37
449 lines (380 loc) · 16.1 KB
/
integration-tests.yml
File metadata and controls
449 lines (380 loc) · 16.1 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
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
name: Integration Tests
on:
push:
branches: [ master, develop ]
paths:
- 'integration-tests/**'
- 'iterableapi/**'
- 'iterableapi-ui/**'
pull_request:
branches: [ master, develop ]
paths:
- 'integration-tests/**'
- 'iterableapi/**'
- 'iterableapi-ui/**'
schedule:
# Run integration tests daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
integration-tests:
name: Integration Tests
runs-on: macos-latest
strategy:
matrix:
api-level: [29] # Focus on API 29 for MVP testing
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Android SDK
uses: android-actions/setup-android@v2
- name: Create local.properties
run: |
echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties
echo "ndk.dir=$ANDROID_SDK_ROOT/ndk" >> local.properties
- name: Accept Android SDK Licenses
run: |
echo "Accepting Android SDK licenses..."
yes | sdkmanager --licenses || true
echo "SDK licenses accepted"
- name: Install Android System Images
run: |
echo "Installing Android system images for API level ${{ matrix.api-level }}..."
sdkmanager --list | grep "system-images;android-${{ matrix.api-level }}"
sdkmanager "system-images;android-${{ matrix.api-level }};google_apis;x86_64"
sdkmanager "system-images;android-${{ matrix.api-level }};google_apis;x86"
echo "System images installed successfully"
- name: Setup Google Services Configuration
run: |
echo "Setting up Google Services configuration for CI..."
# Ensure the google-services.json file exists for the build
if [ ! -f "integration-tests/google-services.json" ]; then
echo "Creating google-services.json from template..."
cp integration-tests/google-services.json.template integration-tests/google-services.json
fi
echo "Google Services configuration ready"
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Create Android Virtual Device
run: |
echo "Creating AVD for API level ${{ matrix.api-level }}..."
# List available system images for debugging
echo "Available system images:"
sdkmanager --list | grep "system-images;android-${{ matrix.api-level }}" || echo "No system images found for API ${{ matrix.api-level }}"
# Try to create AVD with x86_64 first, fallback to x86
if sdkmanager --list | grep -q "system-images;android-${{ matrix.api-level }};google_apis;x86_64"; then
echo "Creating AVD with x86_64 system image..."
echo "no" | avdmanager create avd \
-n "test_device_api_${{ matrix.api-level }}" \
-k "system-images;android-${{ matrix.api-level }};google_apis;x86_64" \
-c 1536M \
-f
elif sdkmanager --list | grep -q "system-images;android-${{ matrix.api-level }};google_apis;x86"; then
echo "Creating AVD with x86 system image..."
echo "no" | avdmanager create avd \
-n "test_device_api_${{ matrix.api-level }}" \
-k "system-images;android-${{ matrix.api-level }};google_apis;x86" \
-c 1536M \
-f
else
echo "Error: No suitable system images found for API level ${{ matrix.api-level }}"
echo "Available system images:"
sdkmanager --list | grep "system-images" | head -20
exit 1
fi
echo "AVD created successfully"
- name: Start Android Emulator
run: |
echo "Starting emulator for API level ${{ matrix.api-level }}..."
$ANDROID_SDK_ROOT/emulator/emulator \
-avd test_device_api_${{ matrix.api-level }} \
-no-audio \
-no-window \
-no-snapshot \
-camera-back none \
-camera-front none \
-gpu swiftshader_indirect \
-memory 1536 \
-cores 1 \
-no-boot-anim \
-no-snapshot-load \
-no-snapshot-save \
-wipe-data &
echo "Emulator started in background"
- name: Wait for emulator
run: |
echo "Waiting for emulator to be ready..."
# Wait for device to be detected
timeout=60
counter=0
while ! adb devices | grep -q "emulator.*device" && [ $counter -lt $timeout ]; do
echo "Waiting for emulator to be detected... ($counter/$timeout)"
sleep 2
counter=$((counter + 2))
done
if ! adb devices | grep -q "emulator.*device"; then
echo "ERROR: Emulator not detected within timeout"
adb devices
exit 1
fi
echo "Emulator detected, waiting for boot completion..."
# Wait for boot completion with shorter intervals
timeout=180 # 3 minutes timeout
counter=0
while [ "`adb shell getprop sys.boot_completed 2>/dev/null`" != "1" ] && [ $counter -lt $timeout ]; do
echo "Waiting for boot completion... ($counter/$timeout)"
sleep 3
counter=$((counter + 3))
# Check if device is still online
if ! adb devices | grep -q "emulator.*device"; then
echo "ERROR: Emulator went offline during boot"
adb devices
exit 1
fi
done
if [ "`adb shell getprop sys.boot_completed 2>/dev/null`" != "1" ]; then
echo "ERROR: Emulator failed to boot within timeout"
echo "Device status:"
adb devices
echo "Last 20 logcat entries:"
adb logcat -d | tail -20
exit 1
fi
echo "Emulator boot completed, setting up..."
# Wait a bit for system to stabilize
sleep 5
# Unlock screen
adb shell input keyevent 82
sleep 2
adb shell input keyevent 82
# Disable animations for stability
adb shell settings put global window_animation_scale 0.0
adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0
# Additional stability settings
adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
# Final stability wait
sleep 5
echo "Emulator setup complete"
- name: Grant notification permissions
run: |
echo "Granting notification permissions..."
adb shell pm grant com.iterable.integration.tests android.permission.POST_NOTIFICATIONS
- name: Verify Emulator Health
run: |
echo "Verifying emulator health before running tests..."
# Check if emulator is responsive
adb shell echo "Emulator is responsive"
# Check system properties
echo "Boot completed: $(adb shell getprop sys.boot_completed)"
echo "System ready: $(adb shell getprop dev.bootcomplete)"
# Check available memory
adb shell cat /proc/meminfo | grep MemAvailable
# Check if system is stable
adb shell getprop ro.build.version.release
adb shell getprop ro.product.model
# Restart ADB to ensure stable connection
echo "Restarting ADB for stable connection..."
adb kill-server
adb start-server
adb wait-for-device
# Clear any existing installations
echo "Clearing existing app installations..."
adb uninstall com.iterable.integration.tests || true
adb uninstall com.iterable.integration.tests.test || true
echo "Emulator health check completed"
- name: Run MVP In-App Message Test
env:
ITERABLE_API_KEY: ${{ secrets.ITERABLE_API_KEY }}
ITERABLE_SERVER_API_KEY: ${{ secrets.ITERABLE_SERVER_API_KEY }}
run: |
echo "Running MVP In-App Message test only..."
# Check emulator status before running tests
echo "Checking emulator status..."
adb devices
adb shell getprop sys.boot_completed
# Run the test with simplified command
cd integration-tests
./gradlew connectedCheck \
-Pandroid.testInstrumentationRunnerArguments.class="com.iterable.integration.tests.InAppMessageIntegrationTest#testInAppMessageMVP" \
--info \
--stacktrace \
--no-daemon \
--max-workers=1
- name: Generate Test Report
if: always()
run: |
echo "Generating test report..."
./gradlew :integration-tests:jacocoIntegrationTestReport
- name: Collect Test Logs
if: always()
run: |
echo "Collecting test logs..."
adb logcat -d > integration-tests/build/test-logs.txt
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-results-api-${{ matrix.api-level }}
path: |
integration-tests/build/reports/
integration-tests/build/outputs/
integration-tests/build/test-logs.txt
- name: Upload Coverage Report
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-coverage-api-${{ matrix.api-level }}
path: integration-tests/build/reports/jacoco/
- name: Upload Screenshots (if any)
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-screenshots-api-${{ matrix.api-level }}
path: integration-tests/screenshots/
- name: Stop emulator
if: always()
run: |
echo "Stopping emulator..."
adb emu kill
integration-tests-nightly:
name: Nightly Integration Tests
runs-on: macos-latest
if: github.event_name == 'schedule'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Android SDK
uses: android-actions/setup-android@v2
- name: Create local.properties
run: |
echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties
echo "ndk.dir=$ANDROID_SDK_ROOT/ndk" >> local.properties
- name: Accept Android SDK Licenses
run: |
echo "Accepting Android SDK licenses..."
yes | sdkmanager --licenses || true
echo "SDK licenses accepted"
- name: Install Android System Images
run: |
echo "Installing Android system images for API level 34..."
sdkmanager --list | grep "system-images;android-34"
sdkmanager "system-images;android-34;google_apis;x86_64"
sdkmanager "system-images;android-34;google_apis;x86"
echo "System images installed successfully"
- name: Setup Google Services Configuration
run: |
echo "Setting up Google Services configuration for CI..."
# Ensure the google-services.json file exists for the build
if [ ! -f "integration-tests/google-services.json" ]; then
echo "Creating google-services.json from template..."
cp integration-tests/google-services.json.template integration-tests/google-services.json
fi
echo "Google Services configuration ready"
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Create Android Virtual Device
run: |
echo "Creating AVD for nightly tests..."
# List available system images for debugging
echo "Available system images:"
sdkmanager --list | grep "system-images;android-34" || echo "No system images found for API 34"
# Try to create AVD with x86_64 first, fallback to x86
if sdkmanager --list | grep -q "system-images;android-34;google_apis;x86_64"; then
echo "Creating AVD with x86_64 system image..."
echo "no" | avdmanager create avd \
-n "nightly_test_device" \
-k "system-images;android-34;google_apis;x86_64" \
-c 2048M \
-f
elif sdkmanager --list | grep -q "system-images;android-34;google_apis;x86"; then
echo "Creating AVD with x86 system image..."
echo "no" | avdmanager create avd \
-n "nightly_test_device" \
-k "system-images;android-34;google_apis;x86" \
-c 2048M \
-f
else
echo "Error: No suitable system images found for API level 34"
echo "Available system images:"
sdkmanager --list | grep "system-images" | head -20
exit 1
fi
echo "AVD created successfully"
- name: Start Android Emulator
run: |
echo "Starting emulator..."
$ANDROID_SDK_ROOT/emulator/emulator \
-avd nightly_test_device \
-no-audio \
-no-window \
-no-snapshot \
-camera-back none \
-camera-front none \
-gpu swiftshader_indirect &
- name: Wait for emulator
run: |
echo "Waiting for emulator..."
adb wait-for-device
adb shell input keyevent 82
adb shell input keyevent 82
- name: Grant notification permissions
run: |
echo "Granting notification permissions..."
adb shell pm grant com.iterable.integration.tests android.permission.POST_NOTIFICATIONS
- name: Run All Integration Tests
env:
ITERABLE_API_KEY: ${{ secrets.ITERABLE_API_KEY }}
ITERABLE_SERVER_API_KEY: ${{ secrets.ITERABLE_SERVER_API_KEY }}
run: |
echo "Running all integration tests..."
./gradlew :integration-tests:connectedCheck --info
- name: Generate Test Report
if: always()
run: |
echo "Generating test report..."
./gradlew :integration-tests:jacocoIntegrationTestReport
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: nightly-integration-test-results
path: |
integration-tests/build/reports/
integration-tests/build/outputs/
- name: Upload Coverage Report
if: always()
uses: actions/upload-artifact@v4
with:
name: nightly-integration-test-coverage
path: integration-tests/build/reports/jacoco/
- name: Stop emulator
if: always()
run: |
echo "Stopping emulator..."
adb emu kill