-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
121 lines (106 loc) · 5.31 KB
/
azure-pipelines.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
variables:
DEVICE_VIDEO_DIR: /mnt/sdcard/DCIM
parameters:
- name: AndroidAPIs
type: object
default:
- name: '22'
arch: 'x86'
- name: '23'
arch: 'x86'
- name: '24'
arch: 'x86'
- name: '25'
arch: 'x86'
- name: '26'
arch: 'x86'
- name: '27'
arch: 'x86'
- name: '28'
arch: 'x86'
- name: '29'
arch: 'x86'
- name: '30'
arch: 'x86'
# there is no x86 image for API 31
# I leave other API on x86 images because API 29 x86_64 does some shenanigans
- name: '31'
arch: 'x86_64'
trigger:
- master
pool:
vmImage: 'macos-latest'
jobs:
- ${{ each value in parameters.AndroidAPIs }}:
- job:
timeoutInMinutes: 40
displayName: API ${{ value.name }}
steps:
- bash: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-${{ value.name }};google_apis;${{ value.arch }}'
# -d 17 for Pixel
# to find out other devices run "avdmanager list device"
# set sdcard standard size explicitely to avoid empty external storage on API 21-22
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n xamarin_android_emulator -k 'system-images;android-${{ value.name }};google_apis;${{ value.arch }}' --sdcard 512M -d 17 --force
$ANDROID_HOME/emulator/emulator -list-avds
echo "Starting emulator"
# increase memory size to 2048M to avoid error "System UI is not responding"
# in the regex \1 means "hw.ramSize=", so we replace number that is placed after "hw.ramSize=" to 2048M.
# More details https://stackoverflow.com/a/4609965/3914914
sed -i 's/^\(hw.ramSize=\).*$/\12048/' ~/.android/avd/xamarin_android_emulator.avd/config.ini
# solution from https://stackoverflow.com/a/16402304 to fix error "System UI is not responding"
sed -i 's/^\(hw.mainKeys=\).*$/\1yes/' ~/.android/avd/xamarin_android_emulator.avd/config.ini
# solution from https://stackoverflow.com/questions/9322540/how-to-change-the-android-emulator-ram-size-from-the-command-line
sed -i 's/^\(vm.heapSize=\).*$/\1256/' ~/.android/avd/xamarin_android_emulator.avd/config.ini
nohup $ANDROID_HOME/emulator/emulator -avd xamarin_android_emulator -gpu swiftshader_indirect -no-window -skin 1080x1920 -no-snapshot -no-audio -no-boot-anim -accel auto -qemu > /dev/null 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0 &
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0 &
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0 &
echo "Emulator started"
displayName: 'Run Android Emulator'
- bash: |
$ANDROID_HOME/platform-tools/adb uninstall com.example.crosswordToLearn
$ANDROID_HOME/platform-tools/adb logcat -c
$ANDROID_HOME/platform-tools/adb logcat > $(Build.ArtifactStagingDirectory)/device-${{ value.name }}.log &
echo $! > logcat.pid
echo "Logcat Started with Process ID: $(cat logcat.pid)"
$ANDROID_HOME/platform-tools/adb shell "mkdir -p $(DEVICE_VIDEO_DIR)"
$ANDROID_HOME/platform-tools/adb shell '''
for i in $(seq 1 1 20)
do
screenrecord --bugreport --verbose --time-limit=180 /mnt/sdcard/DCIM/test"${i}".mp4
done
''' > $(Build.ArtifactStagingDirectory)/video-${{ value.name }}.log &
echo $! > video.pid
echo "Video Recorder Started with Process ID: $(cat video.pid)"
displayName: 'Start Video Record and Logcat'
- bash: |
ln -s ${ANDROID_HOME}/build-tools/31.0.0/d8 ${ANDROID_HOME}/build-tools/31.0.0/dx
ln -s ${ANDROID_HOME}/build-tools/31.0.0/lib/d8.jar ${ANDROID_HOME}/build-tools/31.0.0/lib/dx.jar
./gradlew connectedDebugAndroidTest -Porchestrator=true --info
./gradlew --stop
displayName: 'Run Instrumented Tests'
- task: PublishTestResults@2
displayName: 'Test Results'
inputs:
testResultsFiles: '**/outputs/androidTest-results/**/TEST*.xml'
failTaskOnFailedTests: true
testRunTitle: 'API ${{ value.name }}'
condition: succeededOrFailed()
- bash: |
kill -9 $(cat video.pid) || true
sleep 5
$ANDROID_HOME/platform-tools/adb pull $(DEVICE_VIDEO_DIR) $(Build.ArtifactStagingDirectory)/API_${{ value.name }} || true
kill -9 $(cat logcat.pid) || true
adb kill-server
condition: or(succeeded(), failed())
displayName: 'Copy Videos and Clean Up'
- task: PublishBuildArtifacts@1
condition: or(succeeded(), failed())
displayName: 'Publish Tests Archive'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: '$(Build.BuildId).TestsArchive'
publishLocation: 'Container'