-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpipeline-android.yml
299 lines (246 loc) · 10.4 KB
/
pipeline-android.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
trigger:
# think about using batching to cut down on overlapping runs
#batch: true
branches:
include:
- main
paths:
include:
# common
- 'XamarinPipelineDemo'
- 'XamarinPipelineDemo.NUnit'
- 'XamarinPipelineDemo.UITest'
- 'XamarinPipelineDemo.sln'
# platform
- 'XamarinPipelineDemo.Android'
pool:
vmImage: 'macos-latest'
variables:
- group: android_demo_var_group
- name: appName
value: 'XamarinPipelineDemo'
- name: solution
value: '$(Build.SourcesDirectory)/$(appName).sln'
- name: buildConfiguration
value: 'Release'
- name: outputDir
value: '$(Build.BinariesDirectory)/$(buildConfiguration)'
- name: pipelineBuildNumber
value: $[counter(variables['Build.DefinitionName'], 1)]
- name: finalApkCommonPart
value: '$(Build.ArtifactStagingDirectory)/$(appName)_$(Build.BuildNumber)_$(pipelineBuildNumber)'
- name: finalApkPathUnsigned
value: '$(finalApkCommonPart)_Unsigned.apk'
- name: finalApkPathSigned
value: '$(finalApkCommonPart)_Signed.apk'
- name: androidDir
value: '$(Build.SourcesDirectory)/$(appName).Android'
- name: androidPipelineDir
value: '$(androidDir)/AzureDevOps'
- name: nugetPackageDir
value: '$(System.DefaultWorkingDirectory)/packages'
- name: uiTestDir
value: '$(Build.SourcesDirectory)/$(appName).UITest'
- name: uiTestAssemblyDir
value: '$(uiTestDir)/bin/$(buildConfiguration)'
- name: uiTestResultPath
value: '$(Build.ArtifactStagingDirectory)/uitest_result.xml'
- name: uiTestLogPath
value: '$(Build.ArtifactStagingDirectory)/uitest.log'
- name: adb
value: '$ANDROID_HOME/platform-tools/adb'
- name: emulator
value: '$ANDROID_HOME/emulator/emulator'
- name: appCenterOutputDir
value: '$(Build.ArtifactStagingDirectory)/AppCenterTest'
- name: appCenterTestResultsDir
value: '$(appCenterOutputDir)/TestResults'
- name: appCenterOrgName
value: 'JacobEgnerDemos'
- name: wantAppCenterUiTests
value: true
- name: wantEmulatorUiTests
value: true
# set this to false when things are working and you don't need to debug
# pipeline problems
- name: System.Debug
value: true
################################################################################
steps:
################################################################################
# build app and make APK
# doing a new Xamarin Android app pipeline gets you this task
- task: NuGetToolInstaller@1
# doing a new Xamarin Android app pipeline gets you a simpler form of this task
- task: NuGetCommand@2
displayName: 'nuget-restore solution'
inputs:
restoreSolution: '$(solution)'
- task: PowerShell@2
displayName: 'Set build-based Android app version'
inputs:
filePath: '$(androidPipelineDir)/AndroidSetVersion.ps1'
arguments: >
-manifestPath '$(androidDir)/Properties/AndroidManifest.xml'
-versionCodeBase 0
-versionCodeOffset $(pipelineBuildNumber)
-versionName '$(Build.BuildNumber)'
- task: XamarinAndroid@1
inputs:
projectFile: '**/*droid*.csproj'
outputDir: '$(outputDir)'
configuration: '$(buildConfiguration)'
- pwsh: Get-ChildItem -Recurse "$(outputDir)/*.apk" | ForEach-Object { Copy-Item $_ -Destination "$(finalApkPathUnsigned)" }
displayName: 'copy and rename unsigned apk'
# REMINDER: You need to upload
# XamarinPipelineDemo.Android/AzureDevops/example.keystore as a secure file and
# make android_demo_var_group variable group with the following variables...
# androidKeystoreSecureFileName: example.keystore
# androidKeyAlias: androiddebugkey
# androidKeystorePassword: android
# androidKeyPassword: android
- task: AndroidSigning@3
displayName: 'sign APK with example keystore'
inputs:
apkFiles: '$(outputDir)/*.apk'
apksignerKeystoreFile: '$(androidKeystoreSecureFileName)'
apksignerKeystoreAlias: '$(androidKeyAlias)'
apksignerKeystorePassword: '$(androidKeystorePassword)'
apksignerArguments: '--verbose --out $(finalApkPathSigned)'
- task: PublishBuildArtifacts@1
displayName: 'publish APK artifacts'
inputs:
artifactName: 'apks'
################################################################################
# unit tests
# our unit test project is .net core, so "dotnet test" works on it
- task: DotNetCoreCLI@2
displayName: 'unit tests'
inputs:
command: 'test'
projects: '**/*NUnit*.csproj'
configuration: '$(buildConfiguration)'
testRunTitle: 'Unit Tests'
################################################################################
# UI tests, preparatory steps common to App Center and emulator
- task: MSBuild@1
displayName: 'build ui tests'
condition: >
and(
succeeded(),
or(
eq(variables.wantAppCenterUiTests, true),
eq(variables.wantEmulatorUiTests, true)
)
)
inputs:
solution: '**/*UITest*.csproj'
configuration: '$(buildConfiguration)'
################################################################################
# emulator UI tests
# lots of inspiration from https://medium.com/genetec-tech/android-ui-testing-in-azure-devops-81bbe7cea9fd
# older sources of inspiration from...
# https://github.com/janpio/azure-pipelines-android_emulator
# https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/android?view=azure-devops#test-on-the-android-emulator
- bash: |
set -o xtrace
$ANDROID_HOME/tools/bin/sdkmanager --list
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-30;google_apis;x86'
displayName: 'install Android image'
condition: and(succeeded(), eq(variables.wantEmulatorUiTests, true))
- bash: |
set -o xtrace
$(emulator) -list-avds
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n uitest_android_emulator -k 'system-images;android-30;google_apis;x86' --force
$(emulator) -list-avds
displayName: 'create AVD'
condition: and(succeeded(), eq(variables.wantEmulatorUiTests, true))
- bash: |
set -o xtrace
$(adb) devices
nohup $(emulator) -avd uitest_android_emulator -no-snapshot -no-boot-anim -gpu auto -qemu > /dev/null 2>&1 &
displayName: 'start Android emulator'
condition: and(succeededOrFailed(), eq(variables.wantEmulatorUiTests, true))
- bash: |
set -o xtrace
$(adb) wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$(adb) devices
displayName: 'wait for Android emulator'
condition: and(succeeded(), eq(variables.wantEmulatorUiTests, true))
timeoutInMinutes: 5
# have to run nunit3-console directly; as of 2020-12-17, even though "dotnet
# run" works with Mono to run .net framework projects, "dotnet test" does not
# work the same project; see open issue https://github.com/mono/mono/issues/6984
- pwsh: |
Set-PSDebug -Trace 1
$env:UITEST_APK_PATH = "$(finalApkPathSigned)"
$testAssemblies = Get-Item "$(uiTestDir)/bin/$(buildConfiguration)/$(appName).UITest*.dll"
nunit3-console $testAssemblies --output="$(uiTestLogPath)" --result="$(uiTestResultPath)"
displayName: 'run android emulator ui tests'
condition: and(succeeded(), eq(variables.wantEmulatorUiTests, true))
continueOnError: true
timeoutInMinutes: 120
- task: PublishBuildArtifacts@1
displayName: 'publish emulator ui test log artifact'
condition: and(succeededOrFailed(), eq(variables.wantEmulatorUiTests, true))
continueOnError: true
inputs:
artifactName: 'Android emulator UI test log'
pathToPublish: '$(uiTestLogPath)'
- task: PublishTestResults@2
condition: and(succeededOrFailed(), eq(variables.wantEmulatorUiTests, true))
inputs:
testRunTitle: 'Android Emulator UI Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(uiTestResultPath)'
# Android tests may randomly fail because of the System UI not responding (if you're using Prism);
# see https://github.com/PrismLibrary/Prism/issues/2099 ;
# tests may also fail due to pool agent problems;
# using the following line still makes builds have warning status when UI tests fail
failTaskOnFailedTests: false
################################################################################
# AppCenter UI tests
# default nodejs version (v12) is not compatible with stuff used in AppCenterTest task
# https://github.com/microsoft/appcenter-cli/issues/696#issuecomment-553218361
- task: UseNode@1
displayName: 'Use Node 10.15.1'
condition: and(succeeded(), eq(variables.wantAppCenterUiTests, true))
inputs:
version: 10.15.1
- task: AppCenterTest@1
condition: and(succeeded(), eq(variables.wantAppCenterUiTests, true))
continueOnError: true
inputs:
appFile: '$(finalApkPathSigned)'
appSlug: '$(appCenterOrgName)/$(appName)' # orgname or username, then '/', then app name
devices: '$(appCenterOrgName)/demo_device_set' # uses same orgname or username, then '/', then device set name
frameworkOption: 'uitest'
runOptions: --test-output-dir "$(appCenterOutputDir)" # only needed if publishing test results in Azure DevOps
serverEndpoint: 'AppCenterConnectionUserBasedFullAccess' # make a App Center user API token, then add service connection in Azure DevOps
uiTestBuildDirectory: '$(uiTestAssemblyDir)' # directory that contains the uitest assemblies, not the build directory
uiTestToolsDirectory: '$(uiTestAssemblyDir)' # build process puts test-cloud.exe in assembly dir
- pwsh: Expand-Archive "$(appCenterOutputDir)/nunit_xml_zip.zip" -DestinationPath "$(appCenterTestResultsDir)"
displayName: 'unzip App Center test results zip'
condition: and(succeededOrFailed(), eq(variables.wantAppCenterUiTests, true))
continueOnError: true
- task: PublishTestResults@2
displayName: 'simple-publish App Center UI test results'
condition: and(succeededOrFailed(), eq(variables.wantAppCenterUiTests, true))
inputs:
testRunTitle: 'Android App Center UI Test Run (simple publish)'
testResultsFormat: 'NUnit'
testResultsFiles: '$(appCenterTestResultsDir)/*.xml'
- pwsh: |
Get-ChildItem "$(appCenterTestResultsDir)/*.xml" | ForEach-Object { Write-Output `
( "##vso[results.publish " `
+ "runTitle=Android App Center UI Test Run $($_.BaseName);" `
+ "resultFiles=$($_.FullName);" `
+ "type=NUnit;" `
+ "mergeResults=false;" `
+ "publishRunAttachments=true;" `
+ "failTaskOnFailedTests=false;" `
+ "testRunSystem=VSTS - PTR;" `
+ "]" `
)}
displayName: 'complicated-publish App Center UI test results with device name'
condition: and(succeededOrFailed(), eq(variables.wantAppCenterUiTests, true))