-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (151 loc) · 6.63 KB
/
installunityeditor.yml
File metadata and controls
172 lines (151 loc) · 6.63 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
name: Install the required Unity Editor on server
on:
workflow_call:
inputs:
build-target:
description: "Platform the job should run under"
required: true
type: string
unityversion:
description: "The version of Unity to validate"
required: true
type: string
modules:
description: 'The additional modules to install with the editor (i.e "webgl android lumin")'
type: string
required: false
jobs:
validate_unity_install:
name: Validate Unity Hub and Editor install required for Project
runs-on: ${{ inputs.build-target }}
outputs:
unityversion: ${{ steps.validate.outputs.unityversion }}
editor-path: ${{ steps.validate.outputs.editor-path }}
steps:
- name: Script Version
run: |
echo "::group::Script Versioning"
$scriptVersion = "1.0.1"
echo "Build Script Version: $scriptVersion"
echo "::endgroup::"
shell: pwsh
- id: validate
name: 'Unity Project Validation'
run: |
echo "::group::Validating input"
$unityVersion = '${{ inputs.unityversion }}'
echo "Unity version is $unityVersion"
echo "::endgroup::"
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"
if ([string]::IsNullOrEmpty($modulesString))
{
$modules = @('windows-il2cpp', 'universal-windows-platform', 'webgl', 'android')
}
#"Unity Hub.exe" -- --headless help
#. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help
function unity-hub {
$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList (@('--','--headless') + $args.Split(" "))
}
}
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"
if ([string]::IsNullOrEmpty($modulesString))
{
$modules = @('mac-il2cpp', 'ios', 'webgl', 'android')
}
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
function unity-hub {
$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList (@('--','--headless') + $args.Split(" "))
}
}
elseif ( $global:PSVersionTable.OS.Contains("Linux") )
{
$hubPath = "$HOME/Unity Hub/UnityHub.AppImage"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
if ([string]::IsNullOrEmpty($modulesString))
{
$modules = @('linux-il2cpp', 'webgl', 'android')
}
# /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(" ")
}
}
if ( -not (Test-Path "$hubPath") ) {
echo "$hubPath path not found!"
exit 1
}
echo "::endgroup::"
echo "::group::Checking Unity Editor Installation"
$editorPath = "{0}{1}{2}" -f $editorRootPath,$unityVersion,$editorFileEx
if (Test-Path -Path $editorPath){
echo "Editor already installed, exiting..."
echo ""
echo "UnityEditor path set to: $editorPath"
echo "editor-path=$editorPath" >> $env:GITHUB_OUTPUT
echo "unityversion=$unityVersion" >> $env:GITHUB_OUTPUT
echo "::endgroup::"
exit 0
}
else {
function GetString($InputString, $InputPattern, $MatchIndex) {
$regExResult = $InputString | Select-String -Pattern $InputPattern
$regExResult.Matches[$MatchIndex].Value
}
function Get-unity-changeset
{
if ($unityVersion.Contains('a'))
{
$versionPageUrl = 'https://unity3d.com/unity/alpha/' + $unityVersion;
} elseif ($unityVersion.Contains('b')) {
$versionPageUrl = 'https://unity3d.com/unity/beta/' + $unityVersion;
} elseif ($unityVersion.Contains('f')) {
$urlSuffix = GetString -InputString $unityVersion -InputPattern '[.0-9]+' -MatchIndex 0;
$versionPageUrl = 'https://unity3d.com/unity/whats-new/' + $urlSuffix;
}
$p = (New-Object System.Net.WebClient).DownloadString($versionPageUrl)
$unityChangeSetText = GetString -InputString $p -InputPattern 'Changeset:<\/span>[ \n]*([a-z0-9]{12})' -MatchIndex 0;
GetString -InputString $unityChangeSetText -InputPattern '[a-z0-9]{12}' -MatchIndex 0
}
$unityChangeSet = Get-unity-changeset
echo "Installing $unityVersion ($unityChangeSet)..."
$installArgs = @("install","--version $unityVersion","--changeset $unityChangeSet","--cm")
foreach ( $module in $modules ) {
$installArgs += '-m'
$installArgs += $module
echo " with module: $module"
}
$installArgsString = $installArgs -join " "
unity-hub $installArgsString
echo ""
if ( $global:PSVersionTable.OS.Contains("Linux") ) {
$installedEditors = & xvfb-run --auto-servernum "$hubPath" -- --headless editors -i | Out-String
}
else {
$installedEditors = & $hubPath -- --headless editors -i | Out-String
}
echo $installedEditors
}
if ( -not (Test-Path -Path $editorPath) )
{
Write-Error "Failed to validate installed editor path at $editorPath"
exit 1
}
echo ""
echo "UnityEditor path set to: $editorPath"
echo "editor-path=$editorPath" >> $env:GITHUB_OUTPUT
echo "unityversion=$unityVersion" >> $env:GITHUB_OUTPUT
echo "::endgroup::"
exit 0
shell: pwsh