Repository navigation
185 lines (164 loc) · 7.26 KB
/
Copy pathvalidateunityinstall.yml
File metadata and controls
185 lines (164 loc) · 7.26 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
name: Validate the Unity Build environment 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
outputs:
unityeditorversion:
description: "Returns the version of Unity Editor the UPM package requires"
value: ${{ jobs.validate_unity_install.outputs.unityversion }}
unityeditorinstalled:
description: "Returns the version of Unity Editor the UPM package requires"
value: ${{ jobs.validate_unity_install.outputs.editorinstalled }}
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 }}
editorinstalled: ${{ steps.validate.outputs.editorinstalled }}
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 }}'
$installedResult = 0
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"
#"Unity Hub.exe" -- --headless help
#. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help
function unity-hub
{
& $hubPath -- --headless $args.Split(" ") | Out-String
}
}
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"
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
function unity-hub
{
& $hubPath -- --headless $args.Split(" ") | Out-String
}
}
elseif ( $global:PSVersionTable.OS.Contains("Linux") )
{
$hubPath = "$HOME/Unity Hub/UnityHub.AppImage"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
# /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::Checking Hub Installation"
# Install hub if not found
if ( -not (Test-Path -Path "$hubPath") ) {
echo "$(Get-Date): Downloading Unity Hub..."
$baseUrl = "https://public-cdn.cloud.unity3d.com/hub/prod";
$outPath = $PSScriptRoot
$wc = New-Object System.Net.WebClient
echo "$(Get-Date): Download Complete, Starting installation..."
if ((-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT")) {
$wc.DownloadFile("$baseUrl/UnityHubSetup.exe", "$outPath/UnityHubSetup.exe")
$startProcessArgs = @{
'FilePath' = "$outPath/UnityHubSetup.exe";
'ArgumentList' = @('/S');
'PassThru' = $true;
'Wait' = $true;
}
# Run Installer
$process = Start-Process @startProcessArgs
if ( $process.ExitCode -ne 0) {
Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)"
exit 1
}
}
elseif ($global:PSVersionTable.OS.Contains("Darwin")) {
$package = "UnityHubSetup.dmg"
$downloadPath = "$outPath/$package"
$wc.DownloadFile("$baseUrl/$package", $downloadPath)
$dmgVolume = (sudo hdiutil attach $downloadPath -nobrowse) | Select-String -Pattern '\/Volumes\/.*' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | select-object -first 1
echo $dmgVolume
$dmgAppPath = (find "$DMGVolume" -name "*.app" -depth 1)
echo $dmgAppPath
sudo cp -rf "`"$dmgAppPath`"" "/Applications"
hdiutil unmount $dmgVolume
}
elseif ($global:PSVersionTable.OS.Contains("Linux")) {
mkdir -pv "$HOME/Unity Hub" "$HOME/.config/Unity Hub" "$editorRootPath"
sudo apt-get update
sudo apt-get install -y libgconf-2-4 libglu1 libasound2 libgtk2.0-0 libgtk-3-0 libnss3 zenity xvfb
#https://www.linuxdeveloper.space/install-unity-linux/
$wc.DownloadFile("$baseUrl/UnityHub.AppImage", "$hubPath")
chmod -v a+x "$hubPath"
touch "$HOME/.config/Unity Hub/eulaAccepted"
}
}
if ( -not (Test-Path "$hubPath") ) {
Write-Error "$hubPath path not found!"
exit 1
}
function GetString($InputString, $InputPattern, $MatchIndex) {
$regExResult = $InputString | Select-String -Pattern $InputPattern
$regExResult.Matches[$MatchIndex].Value
}
if($unityVersion.Length -lt 10)
{
echo 'Short version of Version provided, finding latest full unity version number'
$InstalledUnityVersions = unity-hub editors -r
$unityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,7}" -MatchIndex 0
$unityVersion = $unityVersion.Trim(","," ").Trim()
echo "Long Unity version is $unityVersion"
}
$editorPath = "{0}{1}{2}" -f $editorRootPath,$unityVersion,$editorFileEx
echo "Unity Hub found at `"$hubPath`""
echo ""
echo "Editor root path currently set to: `"$editorRootPath`""
echo ""
echo "Editor path currently set to: `"$editorPath`""
echo ""
unity-hub help
echo ""
echo "::endgroup::"
echo "::group::Checking Unity Editor Installation"
if ( Test-Path -Path $editorPath )
{
$installedResult = 1
}
echo ""
echo "UnityEditor path set to: $editorPath"
echo ""
echo "Editor install result was $installedResult"
echo "unityversion=$unityVersion" >> $env:GITHUB_OUTPUT
echo "editorinstalled=$installedResult" >> $env:GITHUB_OUTPUT
echo "::endgroup::"
exit 0
shell: pwsh