This repository has been archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
311 lines (269 loc) · 14.5 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
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
# This build pipeline is designed for ARM UWP projects, running Unity 2019.x or later, with MRTK Foundation
# If using 2018.x or earlier: Change unity.installComponents to 'Windows, UWP_IL2CPP'
# If not using MRTK Foundation: Change unity.executeMethod to your build method (We recommend basing off the one in MRTK Foundation)
# If you want to build x86 UWP builds: In theory should just be able to change vs.appxPlatforms, but it's a TODO
# This pipeline depends on secret variables that you must define within your Azure DevOps!
# unity.username = <Your Unity account username / email>
# unity.password = <Your Unity account password>
# unity.serialkey = <The serial key for your Unity pro licence>
# Without all three, this pipeline will fail to run!
# Unity will be licensed, used, and then unlicensed during the unity and unitytests jobs in this pipeline.
# A Pro license works on 2 machines, and in theory this pipeline will only use one licence at a time.
# However, should there be unexpected errors and deactivation doesn't complete properly, you may need to log into your Unity account and deactivate all.
# Variables predefined for this build process:
variables:
# If true, will run tests, otherwise skip them. If you do not have tests, set to false to increase build speed.
runTests: false
# The path to the folder which contains the Assets folder of the project.
# If your Unity project is located in a subfolder of your repo, make sure it is reflected in this.
unity.projectPath: '$(System.DefaultWorkingDirectory)/'
# If you are using Unity 2019 or later, leave this alone!
unity.installComponents: 'Windows, Android'
# If you are using Unity 2018 or earlier, comment out the above and uncomment below:
# unity.installComponents: 'Windows, UWP_IL2CPP'
# Explanation: In Unity 2019 and later, .NET scripting was removed. You no longer need to specify 'UWP_IL2CPP', it's now simply 'UWP'!
# The build method of the Unity project. This assumes you have MRTK in your project, and uses its build script.
# If you want to customize your build script, change the method name here:
unity.executeMethod: 'Microsoft.MixedReality.Toolkit.Build.Editor.UnityPlayerBuildTools.StartCommandLineBuild'
# Are we buolding an .appx for x86 or ARM?
# TODO: Theoretically, could expect to use 'x86|ARM' to build for both HL1 and 2, but yet to get that to work.
vs.appxPlatforms: 'ARM'
# I would not expect you to have to change the rest of these unless you had a special reason:
unity.targetBuild: 'Android'
unity.outputPath: '/Builds/WSAPlayer'
unity.editorPath: '/Editor/Unity.exe'
vs.packagePath: '/AppPackages'
# This also needs to be passed to the install template, along with unity.projectPath
unity.installFolder: 'C:/Program Files/Unity/Hub/Editor/'
# What causes us to build? A push to master or a feature branch causes us to build...
trigger:
batch: true
branches:
include:
- master
- feature/*
# Windows machine with Visual Studio 2019:
pool:
vmImage: 'windows-2019'
# Two jobs in this pipeline:
# - Build the Unity
# - Run Unity tests
# Note: The build job can be uncommented and broken up into two jobs, for when that makes sense.
jobs:
# Install Unity (from cache or download) then create Visual Studio project from Unity
- job: unity
displayName: Unity Build
variables:
installCached: false
# Try to ensure that we have the right secrets set up to continue, otherwise fail the job:
condition: or( not(variables['unity.username']), not(variables['unity.password']), not(variables['unity.serialKey']) )
steps:
# What version of Unity does the project say that it wants?:
- task: UnityGetProjectVersionTask@1
name: unitygetprojectversion
displayName: Calling UnityGetProjectVersionV1 from unity-azure-pipelines-tasks extension
inputs:
unityProjectPath: '$(unity.projectPath)'
# TODO: This is the start of code that is repeated in other jobs, and ought to be done via a seperate file template.
# Do we have that Unity installation cached? If so, install from cache:
# (Note: The key is the hashed contents of the ProjectVersion.txt file)
# What is this? See https://docs.microsoft.com/en-us/azure/devops/pipelines/caching/index?view=azure-devops
- task: CacheBeta@0
displayName: Check if Unity installation is cached
inputs:
key: $(Agent.OS) | "$(unitygetprojectversion.projectVersion)" | "$(unity.installComponents)"
path: "$(unity.installFolder)$(unitygetprojectversion.projectVersion)"
cacheHitVar: installCached
# Install the Unity setup module (if we aren't cached):
- task: PowerShell@2
displayName: Install Unity
condition: and(succeeded(), ne(variables['installCached'], true))
inputs:
targetType: 'inline'
script: |
Install-Module -Name UnitySetup -AllowPrerelease -Force -AcceptLicense
# Download and run the installer for Unity Components defined in unity.installComponents:
- task: PowerShell@2
displayName: Installing Unity Components '$(unity.installComponents)'
condition: and(succeeded(), ne(variables['installCached'], true))
inputs:
targetType: 'inline'
script: |
Install-UnitySetupInstance -Installers (Find-UnitySetupInstaller -Version '$(unitygetprojectversion.projectVersion)' -Components $(unity.installComponents)) -Verbose
# TODO: This is the end of code that is repeated in other jobs, and ought to be done via a seperate file template.
# Build the project with Unity using the script defined in unity.executeMethod:
- task: UnityBuildTask@3
displayName: Calling UnityBuildTask@3 from unity-azure-pipelines-tasks extension
name: runbuild
inputs:
buildScriptType: existing
scriptExecuteMethod: '$(unity.executeMethod)'
buildTarget: '$(unity.targetBuild)'
unityProjectPath: '$(unity.projectPath)'
outputPath: '$(Build.BinariesDirectory)'
# Publish the Solution folder:
- task: PublishPipelineArtifact@0
displayName: 'Publish Pipeline Artifact'
inputs:
artifactName: 'sln'
targetPath: '$(unity.projectPath)$(unity.outputPath)'
# Until we have a Unity serial key management system, the unity and slnbuild jobs can be merged for speed.
# # Build the Visual Studio solution generated from the previous job and create a package.
# - job: slnbuild
# displayName: Build Visual Studio project
# dependsOn: unity
# condition: succeeded()
# variables:
# installCached: false
# unityversion: $[ dependencies.unity.outputs['unitygetprojectversion.projectVersion'] ]
# steps:
# # Skip checking out repository
# - checkout: none
# # Download artifacts from last job
# - task: DownloadPipelineArtifact@2
# displayName: 'Download Pipeline Artifacts'
# inputs:
# artifactName: 'sln'
# targetPath: $(Build.SourcesDirectory)
# # TODO: This is the start of code that is repeated from the unity job, and ought to be done via a seperate file template.
# # Do we have that Unity installation cached? If so, install from cache:
# # (Note: The key is the hashed contents of the ProjectVersion.txt file)
# # What is this? See https://docs.microsoft.com/en-us/azure/devops/pipelines/caching/index?view=azure-devops
# - task: CacheBeta@0
# displayName: Check if Unity installation is cached
# inputs:
# key: $(Agent.OS) | "$(unityversion)" | "$(unity.installComponents)"
# path: "$(unity.installFolder)$(unityversion)"
# cacheHitVar: installCached
# # Install the Unity setup module (if we aren't cached):
# - task: PowerShell@2
# displayName: Install Unity
# condition: and(succeeded(), ne(variables['installCached'], true))
# inputs:
# targetType: 'inline'
# script: |
# Install-Module -Name UnitySetup -AllowPrerelease -Force -AcceptLicense
# # Download and run the installer for Unity Components defined in unity.installComponents:
# - task: PowerShell@2
# displayName: Installing Unity Components '$(unity.installComponents)'
# condition: and(succeeded(), ne(variables['installCached'], true))
# inputs:
# targetType: 'inline'
# script: |
# Install-UnitySetupInstance -Installers (Find-UnitySetupInstaller -Version '$(unityversion)' -Components $(unity.installComponents)) -Verbose
# # TODO: This is the end of code that is repeated from the unity job, and ought to be done via a seperate file template.
# Uncomment the above, and change '$(unity.projectPath)$(unity.outputPath)' below to '$(Build.SourcesDirectory)' to resume two seperate jobs
# Find, download, and cache NuGet:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
# Restore the NuGet packages for the solution:
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(unity.projectPath)$(unity.outputPath)/*.sln' # Change to '$(unity.projectPath)$(unity.outputPath)/*.sln' to resume two jobs
# Build the solution with Visual Studio to make an .appx:
- task: MSBuild@1
displayName: 'Build solution'
inputs:
solution: '$(unity.projectPath)$(unity.outputPath)' # Change to '$(unity.projectPath)$(unity.outputPath)' to resume two jobs
configuration: Release
msbuildArguments: '/p:AppxBundle=Always /p:AppxBundlePlatforms="$(vs.appxPlatforms)"'
# Publish the package (.appxbundle/.msixbundle) that we just built:
- task: PublishPipelineArtifact@0
displayName: 'Publish Pipeline Artifact'
inputs:
artifactName: 'apppackages'
targetPath: '$(unity.projectPath)$(unity.outputPath)$(vs.packagePath)' # Change to '$(unity.projectPath)$(unity.outputPath)$(vs.packagePath)' to resume two jobs
# Build the Visual Studio solution generated from the previous job and create a package.
- job: unitytests
dependsOn: unity
condition: and(succeeded(), eq(variables['runTests'], 'true'))
displayName: Unity Tests
variables:
installCached: false
steps:
# What version of Unity does the project say that it wants?:
- task: UnityGetProjectVersionTask@1
name: unitygetprojectversion
displayName: Calling UnityGetProjectVersionV1 from unity-azure-pipelines-tasks extension
inputs:
unityProjectPath: '$(unity.projectPath)'
# TODO: This is the start of code that is repeated from the unity job, and ought to be done via a seperate file template.
# Do we have that Unity installation cached? If so, install from cache:
# (Note: The key is the hashed contents of the ProjectVersion.txt file)
# What is this? See https://docs.microsoft.com/en-us/azure/devops/pipelines/caching/index?view=azure-devops
- task: CacheBeta@0
displayName: Check if Unity installation is cached
inputs:
key: $(Agent.OS) | "$(unitygetprojectversion.projectVersion)" | "$(unity.installComponents)"
path: "$(unity.installFolder)$(unitygetprojectversion.projectVersion)"
cacheHitVar: installCached
# Install the Unity setup module (if we aren't cached):
- task: PowerShell@2
displayName: Install Unity
condition: and(succeeded(), ne(variables['installCached'], true))
inputs:
targetType: 'inline'
script: |
Install-Module -Name UnitySetup -AllowPrerelease -Force -AcceptLicense
# Download and run the installer for Unity Components defined in unity.installComponents:
- task: PowerShell@2
displayName: Installing Unity Components '$(unity.installComponents)'
condition: and(succeeded(), ne(variables['installCached'], true))
inputs:
targetType: 'inline'
script: |
Install-UnitySetupInstance -Installers (Find-UnitySetupInstaller -Version '$(unitygetprojectversion.projectVersion)' -Components $(unity.installComponents)) -Verbose
# TODO: This is the end of code that is repeated from the unity job, and ought to be done via a seperate file template.
# Activate the Unity license (In theory, should deactivate the licence after use!):
- task: UnityActivateLicenseTask@1
displayName: Calling UnityActivateLicenseTask@1 from unity-azure-pipelines-tasks extension
inputs:
username: '$(unity.username)'
password: '$(unity.password)'
serial: '$(unity.serialkey)'
unityEditorsPathMode: 'unityHub'
unityProjectPath: '$(unity.projectPath)'
# Test scripts copied from the MRTK pipeline test script, located here:
# https://github.com/microsoft/MixedRealityToolkit-Unity/blob/mrtk_release/pipelines/templates/tests.yml
# NOTE: If you do not have Unit Tests in your project, you can speed up build times by changing runTests to false.
# Edit mode tests:
# By default, this is left commented out. Can uncomment if you have edit mode tests in your project.
# - powershell: |
# Write-Host "======================= EditMode Tests ======================="
# $logFile = New-Item -Path .\editmode-test-run.log -ItemType File -Force
# $proc = Start-Process -FilePath "$(unity.installFolder)$(unitygetprojectversion.projectVersion)$(unity.editorPath)" -ArgumentList "-projectPath $(unity.projectPath) -runTests -testPlatform editmode -batchmode -logFile $($logFile.Name) -editorTestsResultFile .\test-editmode-default.xml" -PassThru
# $ljob = Start-Job -ScriptBlock { param($log) Get-Content "$log" -Wait } -ArgumentList $logFile.FullName
# while (-not $proc.HasExited -and $ljob.HasMoreData)
# {
# Receive-Job $ljob
# Start-Sleep -Milliseconds 200
# }
# Receive-Job $ljob
# Stop-Job $ljob
# Remove-Job $ljob
# Stop-Process $proc
# displayName: 'Run EditMode tests'
# Play mode tests:
- powershell: |
Write-Host "======================= PlayMode Tests ======================="
$logFile = New-Item -Path .\playmode-test-run.log -ItemType File -Force
$proc = Start-Process -FilePath "$(unity.installFolder)$(unitygetprojectversion.projectVersion)$(unity.editorPath)" -ArgumentList "-projectPath $(unity.projectPath) -runTests -testPlatform playmode -batchmode -logFile $($logFile.Name) -editorTestsResultFile .\test-playmode-default.xml" -PassThru
$ljob = Start-Job -ScriptBlock { param($log) Get-Content "$log" -Wait } -ArgumentList $logFile.FullName
while (-not $proc.HasExited -and $ljob.HasMoreData)
{
Receive-Job $ljob
Start-Sleep -Milliseconds 200
}
Receive-Job $ljob
Stop-Job $ljob
Remove-Job $ljob
Stop-Process $proc
displayName: 'Run PlayMode tests'
# Publish test results:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: NUnit
testResultsFiles: 'test*.xml'
failTaskOnFailedTests: true