-
-
Notifications
You must be signed in to change notification settings - Fork 174
423 lines (350 loc) · 17.4 KB
/
rununitysinglebuild.yml
File metadata and controls
423 lines (350 loc) · 17.4 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
name: Run Limited Unity Builds
on:
workflow_call:
inputs:
unityVersion:
description: "The version of Unity to validate on"
required: true
type: string
dependencies:
description: "json array of dependencies and their targets"
required: false
type: string
jobs:
run_build:
name: Run Unity Build process
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macOS
build-target: iOS
- os: windows
build-target: Android
- os: windows
build-target: StandaloneWindows64
- os: windows
build-target: WSAPlayer
steps:
- name: Script Version
run: |
echo "::group::Script Versioning"
$scriptVersion = "1.0.0"
echo "Build Script Version: $scriptVersion"
echo "::endgroup::"
shell: pwsh
- uses: actions/checkout@v3
with:
submodules: recursive
clean: true
- id: build
name: 'Run Unity Builds'
run: |
echo "::group::Set Hub and editor locations"
$unityVersion = '${{ inputs.unityVersion }}'
echo "::group::Set Hub and editor locations"
## Set Hub and editor locations
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") )
{
$hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe"
$editorRootPath = "C:\Program Files\Unity\Hub\Editor\"
$editorFileEx = "\Editor\Unity.exe"
$directorySeparatorChar = "\"
#"Unity Hub.exe" -- --headless help
#. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help
function unity-hub
{
& $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline
}
}
elseif ( $global:PSVersionTable.OS.Contains("Darwin") )
{
$hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
$editorRootPath = "/Applications/Unity/Hub/Editor/"
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$directorySeparatorChar = "/"
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
function unity-hub
{
& $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline
}
}
elseif ( $global:PSVersionTable.OS.Contains("Linux") )
{
$hubPath = "$HOME/Unity Hub/UnityHub.AppImage"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
$directorySeparatorChar = "/"
# /UnityHub.AppImage --headless help
# xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help
function unity-hub
{
xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ")
}
}
echo "::endgroup::"
echo "::group::Get String function to query a string for a value"
function GetString($InputString, $InputPattern, $MatchIndex)
{
$regExResult = $InputString | Select-String -Pattern $InputPattern
if($regExResult.Length -gt 0)
{
return $regExResult.Matches[$MatchIndex].Value
}
else
{
return 0
}
}
function Get-LetterCount
{
Param ([string]$string)
return $string.Length
}
echo "::endgroup::"
echo "::group::Find Installed Unity version based on input"
echo "Unity hub path is {$hubPath}"
echo "Requested unity version is {$unityVersion}"
$InstalledUnityVersions = unity-hub editors
$editorRootPath = unity-hub ip -g
echo "Installed unity versions are {$InstalledUnityVersions}"
echo "Unity install path is {$editorRootPath}"
$versionLength = Get-LetterCount $unityVersion
if ($versionLength -eq 4) {
$queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,7}" -MatchIndex 0
}
elseif ($versionLength -eq 6) {
$queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,5}" -MatchIndex 0
}
else {
$queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0
}
echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}"
if ($queryUnityVersion -ne 0)
{
$unityVersion = $queryUnityVersion.Trim(","," ").Trim()
echo "Long Unity version is $unityVersion"
}
else
{
echo "Unity $unityVersion not found on this machine, skipping"
exit 0
}
echo "::endgroup::"
echo "::group::Search for Editor if not found"
$checkPath = Join-Path $editorRootPath $unityVersion
echo "Testing for editor at $checkPath"
while (-not (Test-Path "$checkPath")) {
$source = $unityVersion.Replace("f1","")
$newversion = $source.Split(".")
$newversion[2] = [int]$newversion[2] - 1
if ([int]$newversion[2] -lt 1) {
echo "Unity ${{ inputs.unityVersion }} not found on this machine, skipping"
exit 0
}
$newunityVersion = "{0}.{1}.{2}f1" -f $newversion[0],$newversion[1],$newversion[2]
echo "Unity $unityVersion not found on this machine, trying $newunityVersion"
$unityVersion = $newunityVersion
$checkPath = Join-Path $editorRootPath $unityVersion
}
echo "::endgroup::"
echo "::group::Set editor locations"
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
echo 'Building using Windows'
$editorFileEx = "/Editor/Unity.exe"
$editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx
function unity-editor {
#$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" "))
& $editorrunpath -batchmode $args.Split(" ") | Out-String
}
}
elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
echo 'Building using Mac'
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx
function unity-editor {
#$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" "))
& $editorrunpath -batchmode $args.Split(" ") | Out-String
}
}
elseif ( $global:PSVersionTable.OS.Contains("Linux") ) {
echo 'Building using Linux'
$editorFileEx = "/Editor/Unity"
$editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx
function unity-editor {
xvfb-run --auto-servernum "$editorrunpath" -batchmode $args.Split(" ")
}
}
else
{
echo 'Unknown build platform'
}
echo "::endgroup::"
echo "::group::Test Unity version is installed"
if ( -not (Test-Path "$editorrunpath") )
{
Write-Error "Editor not Found for $unityVersion"
exit 1
}
else {
echo "Editor Path is {$editorrunpath}"
}
echo "::endgroup::"
echo "::group::Setup logging and run Unit tests"
# Log detail
$logDirectory = "Logs"
if (Test-Path -Path $logDirectory) {
echo "Clearing logs from a previous run"
Remove-item $logDirectory -recurse
}
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
echo "Log Directory: $logDirectory"
$date = Get-Date -Format "yyyyMMddTHHmmss"
# If run manually, the Refname is actually blank, so just use date
if([string]::IsNullOrEmpty(${GITHUB_REF_NAME})) {
$logName = "$logDirectory$directorySeparatorChar$date"
}
else{
$logName = "$logDirectory$directorySeparatorChar${GITHUB_REF_NAME}-$date"
}
$logPath = "$logName.log"
$testsLogPath = "$logName-tests.xml"
echo "Logpath [$logPath]"
echo "TestsPath [$testsLogPath]"
echo "::endgroup::"
echo "::group::Grouping Package in a UPM folder"
$UPMFolderName = 'u'
if ( -not (Test-Path '$UPMFolderName') )
{
New-Item $UPMFolderName -ItemType Directory
}
Move-Item -Path * -Destination $UPMFolderName -exclude $UPMFolderName
echo "::endgroup::"
echo "::group::Creating Temp Unity project"
$TempUnityProjectName = 'P'
unity-editor '-createProject' $TempUnityProjectName -quit
$destinationPath = $TempUnityProjectName + $directorySeparatorChar + 'packages'
Move-Item -Path $UPMFolderName -Destination $destinationPath
echo "::endgroup::"
echo "::group::If required, clone dependencies in to test project"
<# Dependency option requires specific inputs
* A dependency input string in json format, listing each dependency by name and git url, e.g.
$dependencies = '[{"ASADependencies": "github.com/SimonDarksideJ/upmGithubActionsTests.git"}]'
*Note, remove the https:// portion to allow using a PAT to access the repo
The Name of the dependency should ALSO MATCH the name of the branch on the repo where the dependency is held (files intended for the packages folder)
* Additionally, if Manifest entries are required, then a manifest file with those dependencies (and ONLY the new dependancies) should also be in the dependency branch named the same as the branch name
e.g. "ASADependencies.json" - keep the same structure, but only the dependancy entries
!!Does NOT support additional scoped registries at this time! #>
echo "---------------------------------------------"
echo "Read dependancy input value"
if([string]::IsNullOrEmpty('${{ inputs.dependencies }}'))
{
echo "No dependencies provided"
echo "input ${{ inputs.dependencies }}"
echo "------------------------------"
}
else {
echo "dependencies provided, validating"
# Read dependancy input value
$dependencies = '${{ inputs.dependencies }}'
if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}') -or [string]::IsNullOrEmpty('${{ secrets.GIT_PAT }}')){
echo ""
echo "Secrets for GIT_USER_NAME or GIT_PAT missing, please register them with access to this runner"
echo "*Note, Organisation secrets are not accessible to Forked repos and need registering in the local fork"
exit 1
}
echo "---------------------------------------------"
echo "Read dependancy input values as json"
$JSONdependencies = $dependencies | ConvertFrom-Json
echo $JSONdependencies
# Read current Manifest json
$manifestPath = $destinationPath + $directorySeparatorChar + 'manifest.json'
$projectManifest = Get-Content -Path $manifestPath | ConvertFrom-Json
$strArray = $projectManifest.dependencies.PsObject.Properties | ForEach-Object {"$($_.Name)@$($_.Value),"}
echo "---------------------------------------------"
echo "Loop through new dependancies and add them to the project Manifest"
foreach($dependency in $JSONdependencies){
$dependency.PsObject.Properties | ForEach-Object -Process {
$dependencyName = $_.Name
$dependencyPath = $dependencyName.Replace("/","_")
$dependencyURL = $_.Value
echo "---------------------------------------------"
echo "Cloning dependency - Name [$dependencyName] - Path [$dependencyPath] - URL [$dependencyURL]"
$cloneURL = "https://${{ secrets.GIT_USER_NAME }}:${{ secrets.GIT_PAT }}@$dependencyURL"
echo "cloning $dependencyName from $dependencyURL and moving to $destinationPath"
echo "git path - $cloneURL"
# Clone Dependancy repo to destination folder
git clone -b $dependencyName --single-branch $cloneURL $dependencyPath
if( -not (Test-Path -Path "$dependencyPath")){
echo "Unable to clone $dependencyName from $dependencyURL"
exit 1
}
# Move files from clone path into packages folder, if the dependency contains a UPM package then move the entire folder and not just its contents
if (Test-Path -Path "$dependencyPath/package.json") {
$package_json = Get-Content -Path $dependencyPath/package.json | ConvertFrom-Json
$packageName = $package_json.name
Rename-Item $dependencyPath $packageName
echo "Moving whole $packageName UPM package to $destinationPath"
Move-Item -Path "$packageName" -Destination $destinationPath
}
else {
echo "Moving the contents of $dependencyName into the $destinationPath folder"
Move-Item -Path "$dependencyPath/*" -Destination $destinationPath
}
# Get Dependency manifest entries (if applicable)
if (Test-Path -Path "$destinationPath/$dependencyName.json") {
$dependencyManifest = Get-Content -Path "$destinationPath/$dependencyName.json" | ConvertFrom-Json
$dependencyManifest.dependencies.PsObject.Properties | ForEach-Object {
$strArray += "$($_.Name)@$($_.Value),"
}
}
else{
echo "No denendency json found called $destinationPath/$dependencyName.json, skipping adding additional manifest entries"
}
}
}
echo "---------------------------------------------"
# Reformat combined dependancies list
$strArray = $strArray.Trim(",") | ConvertTo-Json
$strArray = $strArray.Replace("@",'":"').Replace("[","{").Replace("]","}")
$strArrayObject = $strArray | ConvertFrom-Json
# Save manifest back to project
$projectManifest.dependencies = $strArrayObject
$projectManifest | ConvertTo-Json | Set-Content -Path "$destinationPath/manifest.json"
echo "Project updated with the following dependencies"
echo "-----------------------------------------------"
echo $projectManifest
}
echo "::endgroup::"
echo "::group::Run build"
echo "---------------------------------------------"
echo "Start Testing"
echo "Unity Command\n[unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }}]"
unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }}
echo "---------------------------------------------"
echo "::group::Unity Unit tests Results"
if (Test-Path $testsLogPath) {
echo "Test Run results for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF}"
echo ""
Select-Xml -Path $testsLogPath -XPath '/test-run/test-suite' | ForEach-Object { "Name: " +$_.Node.name, ", Result: " + $_.Node.result, ", Total Tests: " + $_.Node.total, ", Passed: " + $_.Node.passed, ", Failed: " + $_.Node.failed, ", Skipped: " + $_.Node.skipped }
}
else {
echo "No test results found for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF} at $testsLogPath"
echo ""
}
echo "::endgroup::"
if($LASTEXITCODE -ne '0'){
echo "::group::Unity Unit tests errors"
$exitCode = $testResult.ExitCode
Get-Content $logPath
echo "Build failed due to errors ($LASTEXITCODE), please check the log at $logPath"
echo "::endgroup::"
exit $LASTEXITCODE
}
echo "::endgroup::"
shell: pwsh
- uses: actions/upload-artifact@v3
if: always()
with:
name: unity-build-log
path: Logs/**