-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (141 loc) · 5.88 KB
/
rununitybuild.yml
File metadata and controls
165 lines (141 loc) · 5.88 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
name: Run Unity Builds
on:
workflow_call:
inputs:
build-target:
required: true
type: string
unityversion:
description: "The version of Unity to validate on"
required: true
type: string
projectpath:
description: "The path to the Unity project"
required: true
type: string
jobs:
run_build:
name: Run Unity Build process
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: self-hosted
build-target: Android
- os: self-hosted
build-target: iOS
steps:
- name: Script Version
run: |
echo "::group::Script Versioning"
$scriptVersion = "1.0.2"
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::Warm up for Unity version"
echo 'Unity version is ${{ inputs.unityversion }}'
$unityVersion = '${{ inputs.unityversion }}'
if([string]::IsNullOrEmpty($unityVersion))
{
echo 'Unity version missing, using default'
$unityVersion = '2021.3.14f1'
}
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
echo 'Building using Windows'
$directorySeparatorChar = "\"
$editorRootPath = "C:/Program Files/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity.exe"
$editorrunpath = "$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'
$directorySeparatorChar = "/"
$editorRootPath = "/Applications/Unity/Hub/Editor/"
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$editorrunpath = "$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'
$directorySeparatorChar = "/"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
$editorrunpath = "$editorRootPath$unityVersion$editorFileEx"
function unity-editor {
xvfb-run --auto-servernum "$editorrunpath" -batchmode $args.Split(" ")
}
}
else
{
echo 'Unknown build platform'
}
if ( -not (Test-Path "$editorrunpath") )
{
Write-Error "$editorrunpath path not found!"
exit 1
}
if ( -not (Test-Path "${{ inputs.projectpath }}") )
{
Write-Error "${{ inputs.projectpath }} project path not found!"
exit 1
}
echo "::endgroup::"
echo "::group::Setup logging and run Unit tests"
# Log detail
$logDirectory = "Logs"
if ( -not (Test-Path -Path $logDirectory)) {
$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"
echo "Logpath [$logPath]"
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