Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit 5e88ddf

Browse files
* xrtk/[email protected] - properly handle editor path lookup by architecture * put arch for other build targets don't fail fast * roll back ubuntu runner * add more protections for x86_64 specifications * some improvements * update module installer * try latest set installation path after calling which unityhub on linux * revert mac back to 14 * add some debug * validate our platform * fix platform name check * try another way * more refactoring * can we do it this way? * change mac * tweaks * missing changes * update module installation * fix missing module install * run build * change logs
1 parent 4b827e7 commit 5e88ddf

File tree

5 files changed

+160
-113
lines changed

5 files changed

+160
-113
lines changed

.github/workflows/validate.yml

+5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ jobs:
2222
validate:
2323
runs-on: ${{ matrix.os }}
2424
strategy:
25+
fail-fast: false
2526
matrix:
2627
include:
2728
- os: ubuntu-latest
2829
build-targets: 'StandaloneLinux64 Android iOS'
2930
- os: windows-latest
3031
build-targets: 'StandaloneWindows64 Android iOS'
32+
- os: macos-14
33+
build-targets: 'StandaloneOSX Android iOS'
34+
arch: 'arm64'
3135
- os: macos-latest
3236
build-targets: 'StandaloneOSX Android iOS'
3337

@@ -47,6 +51,7 @@ jobs:
4751
id: unity-setup
4852
with:
4953
build-targets: '${{ matrix.build-targets }}'
54+
architecture: '${{ matrix.arch }}'
5055

5156
- run: |
5257
echo "${{ env.UNITY_EDITOR_PATH }}"

dist/unity-install.ps1

+76-55
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ $vMatches = [regex]::Matches($version, $pattern)
2424
$unityVersion = $vMatches[1].Groups['version'].Value.Trim()
2525
$unityVersionChangeSet = $vMatches[2].Groups['revision'].Value.Trim()
2626

27-
if ( -not ([String]::IsNullOrEmpty($unityVersion))) {
27+
if (-not ([String]::IsNullOrEmpty($unityVersion))) {
2828
Write-Host ""
2929
"UNITY_EDITOR_VERSION=$unityVersion" >> $env:GITHUB_ENV
3030
Write-Host "Unity Editor version set to: $unityVersion"
31+
} else {
32+
Write-Error "Failed to determine editor version to install!"
33+
exit 1
3134
}
3235

33-
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
36+
if ($IsWindows) {
3437
$hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe"
3538
$editorRootPath = "C:\Program Files\Unity\Hub\Editor\"
3639
$editorFileEx = "\Editor\Unity.exe"
@@ -46,8 +49,7 @@ if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform
4649
$p = Start-Process -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList $argList
4750
$p.WaitForExit()
4851
}
49-
}
50-
elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
52+
} elseif ($IsMacOS) {
5153
$hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
5254
$editorRootPath = "/Applications/Unity/Hub/Editor/"
5355
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
@@ -63,8 +65,7 @@ elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
6365
$p = Start-Process -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList $argList
6466
$p.WaitForExit()
6567
}
66-
}
67-
elseif ( $global:PSVersionTable.OS.Contains("Linux") ) {
68+
} elseif ($IsLinux) {
6869
$hubPath = "/usr/bin/unityhub"
6970
$editorRootPath = "$HOME/Unity/Hub/Editor/"
7071
$editorFileEx = "/Editor/Unity"
@@ -79,6 +80,9 @@ elseif ( $global:PSVersionTable.OS.Contains("Linux") ) {
7980
$argsList = $args.Split(" ")
8081
xvfb-run --auto-servernum "$hubPath" --disable-gpu-sandbox --headless $argsList
8182
}
83+
} else {
84+
Write-Error "Unsupported platform: $($global:PSVersionTable.Platform)"
85+
exit 1
8286
}
8387

8488
# Install hub if not found
@@ -88,9 +92,9 @@ if ( -not (Test-Path -Path "$hubPath") ) {
8892
$outPath = $PSScriptRoot
8993
$wc = New-Object System.Net.WebClient
9094

91-
Write-Host "::group::Installing Unity Hub..."
9295

93-
if ((-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT")) {
96+
if ($IsWindows) {
97+
Write-Host "::group::Installing Unity Hub on windows..."
9498
$wc.DownloadFile("$baseUrl/UnityHubSetup.exe", "$outPath/UnityHubSetup.exe")
9599
$startProcessArgs = @{
96100
'FilePath' = "$outPath/UnityHubSetup.exe";
@@ -106,8 +110,8 @@ if ( -not (Test-Path -Path "$hubPath") ) {
106110
Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)"
107111
exit 1
108112
}
109-
}
110-
elseif ($global:PSVersionTable.OS.Contains("Darwin")) {
113+
} elseif ($IsMacOS) {
114+
Write-Host "::group::Installing Unity Hub on masOS..."
111115
$package = "UnityHubSetup.dmg"
112116
$downloadPath = "$outPath/$package"
113117
$wc.DownloadFile("$baseUrl/$package", $downloadPath)
@@ -121,13 +125,16 @@ if ( -not (Test-Path -Path "$hubPath") ) {
121125
sudo mkdir -p "/Library/Application Support/Unity"
122126
sudo chmod 775 "/Library/Application Support/Unity"
123127
touch '/Library/Application Support/Unity/temp'
124-
}
125-
elseif ($global:PSVersionTable.OS.Contains("Linux")) {
128+
} elseif ($IsLinux) {
129+
Write-Host "::group::Installing Unity Hub on ubuntu..."
126130
sudo sh -c 'echo ""deb https://hub.unity3d.com/linux/repos/deb stable main"" > /etc/apt/sources.list.d/unityhub.list'
127131
wget -qO - https://hub.unity3d.com/linux/keys/public | sudo apt-key add -
128132
sudo apt update
129133
sudo apt install -y unityhub
130-
which unityhub
134+
$hubPath = which unityhub
135+
} else {
136+
Write-Error "Unsupported platform: $($global:PSVersionTable.Platform)"
137+
exit 1
131138
}
132139

133140
Write-Host "::endgroup::"
@@ -140,39 +147,42 @@ if ( -not (Test-Path "$hubPath") ) {
140147

141148
Write-Host "Unity Hub found at `"$hubPath`""
142149

143-
# Write-Host "Editor root path currently set to: `"$editorRootPath`""
144-
145150
Write-Host "::group::Unity Hub Options"
146151
Invoke-UnityHub help
147152
Write-Host "::endgroup::"
148153

149154
# only show errors if github actions debug is enabled
150-
#if ($env:GITHUB_ACTIONS -eq "true") {
151-
Invoke-UnityHub --errors
155+
#if ($env:GITHUB_ACTIONS -eq 'true') {
156+
# Invoke-UnityHub --errors
152157
#}
153158

159+
# set the editor path
154160
$editorPath = "{0}{1}{2}" -f $editorRootPath,$unityVersion,$editorFileEx
155161

156-
if ( -not (Test-Path -Path $editorPath)) {
157-
Write-Host "Installing $unityVersion ($unityVersionChangeSet)"
158-
$installArgs = @('install',"--version $unityVersion","--changeset $unityVersionChangeSet",'--cm')
159-
160-
if (-not [string]::IsNullOrEmpty($architecture)) {
161-
$installArgs += "-a $architecture"
162-
}
163-
164-
$addModules = @()
165-
166-
foreach ($module in $modules) {
167-
if ($module -eq 'android') {
168-
$addmodules += 'android-open-jdk'
169-
$addmodules += 'android-sdk-ndk-tools'
162+
# if architecture is set, check if the specific architecture is installed
163+
if (-not [string]::IsNullOrEmpty($architecture)) {
164+
# if an editor path is found, check which architecture it is
165+
if (Test-Path -Path $editorPath) {
166+
# list all editor installations and pick the ones with the matching version from the returned console output
167+
$archEditors = Invoke-UnityHub editors -i | Select-String -Pattern "$unityVersion" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }
168+
169+
# iterate over the editors and check if the version name contains (Intel) for x86_64 or (Apple silicon) for arm64
170+
foreach ($archEditor in $archEditors) {
171+
if ($IsMacOS) {
172+
if ((($archEditor.Contains("(Intel)") -and $architecture -eq 'x86_64')) -or ($archEditor.Contains("(Apple silicon)") -and $architecture -eq 'arm64')) {
173+
# set the editor path based on the editor string that was found using a substring. Split subtring by ',' and take the last element
174+
$editorPath = $archEditor.Substring(0, $archEditor.IndexOf(','))
175+
}
176+
} else {
177+
Write-Error "Architecture lookup not supported for $($global:PSVersionTable.Platform)"
178+
exit 1
179+
}
170180
}
171181
}
182+
}
172183

173-
$modules += $addModules
174-
175-
foreach ($module in $modules) {
184+
function Invoke-Hub-Install($installModules, $installArgs) {
185+
foreach ($module in $installModules) {
176186
$installArgs += '-m'
177187
$installArgs += $module
178188
Write-Host " > with module: $module"
@@ -184,53 +194,64 @@ if ( -not (Test-Path -Path $editorPath)) {
184194
Invoke-UnityHub $installArgsString
185195
Write-Host ""
186196
Write-Host "::endgroup::"
187-
} else {
188-
Write-Host "Intalling modules for $unityVersion ($unityVersionChangeSet)"
189-
$installArgs = @('install-modules',"--version $unityVersion",'--cm')
197+
}
190198

199+
function AddModules {
191200
$addModules = @()
192201

193202
foreach ($module in $modules) {
203+
$addModules += $module
194204
if ($module -eq 'android') {
195-
$addmodules += 'android-open-jdk'
196-
$addmodules += 'android-sdk-ndk-tools'
205+
$jdkModule = $modules | Where-Object { $_ -like 'android-open-jdk*' }
206+
if (-not ($modules | Where-Object { $_ -eq $jdkModule })) {
207+
$addModules += $jdkModule
208+
}
209+
$ndkModule = $modules | Where-Object { $_ -like 'android-sdk-ndk-tools*' }
210+
if (-not ($modules | Where-Object { $_ -eq $ndkModule })) {
211+
$addModules += $ndkModule
212+
}
197213
}
198214
}
199215

200-
$modules += $addModules
216+
return $addModules
217+
}
201218

202-
foreach ($module in $modules) {
203-
$installArgs += '-m'
204-
$installArgs += $module
205-
Write-Host " > with module: $module"
219+
if (-not (Test-Path -Path $editorPath)) {
220+
Write-Host "Installing $unityVersion ($unityVersionChangeSet)"
221+
$installArgs = @('install',"--version $unityVersion","--changeset $unityVersionChangeSet",'--cm')
222+
$installModules = AddModules
223+
224+
if (-not [string]::IsNullOrEmpty($architecture) -and $architecture -ne 'x86_64') {
225+
$installArgs += "-a $architecture"
206226
}
207227

208-
$installArgsString = $installArgs -join " "
228+
Invoke-Hub-Install $installModules $installArgs
229+
} else {
230+
Write-Host "Checking modules for $unityVersion ($unityVersionChangeSet)"
231+
$installArgs = @('install-modules',"--version $unityVersion",'--cm')
232+
$installModules = AddModules
209233

210-
Write-Host "::group::Run unity-hub $installArgsString"
211-
Invoke-UnityHub $installArgsString
212-
Write-Host ""
213-
Write-Host "::endgroup::"
234+
if ($installModules.Count -gt 0) {
235+
Invoke-Hub-Install $installModules $installArgs
236+
}
214237
}
215238

216239
Write-Host "Installed Editors:"
217240
Invoke-UnityHub editors -i
218241

219-
if ( -not (Test-Path -Path $editorPath) ) {
242+
if (-not (Test-Path -Path $editorPath)) {
220243
Write-Error "Failed to validate installed editor path at $editorPath"
221244
exit 1
222245
}
223246

224247
$modulesPath = '{0}{1}{2}modules.json' -f $editorRootPath,$UnityVersion,[IO.Path]::DirectorySeparatorChar
225248

226-
if ( -not (Test-Path -Path $modulesPath)) {
249+
if (-not (Test-Path -Path $modulesPath)) {
227250
$editorPath = "{0}{1}" -f $editorRootPath,$unityVersion
228-
#Write-Host "Cleaning up invalid installation under $editorPath"
229251
Write-Error "Failed to resolve modules path at $modulesPath"
230252

231253
if (Test-Path -Path $editorPath) {
232254
Get-ChildItem $editorPath
233-
# Remove-Item $editorPath -Recurse -Force
234255
}
235256

236257
exit 1
@@ -239,8 +260,8 @@ if ( -not (Test-Path -Path $modulesPath)) {
239260
Write-Host "Modules Manifest: "$modulesPath
240261

241262
foreach ($module in (Get-Content -Raw -Path $modulesPath | ConvertFrom-Json -AsHashTable)) {
242-
if ( ($module.category -eq 'Platforms') -and ($module.visible -eq $true) ) {
243-
if ( -not ($modules -contains $module.id) ) {
263+
if (($module.category -eq 'Platforms') -and ($module.visible -eq $true)) {
264+
if (-not ($modules -contains $module.id)) {
244265
Write-Host " > additional module option: " $module.id
245266
}
246267
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unity-setup",
3-
"version": "7.4.0",
3+
"version": "7.4.1",
44
"description": "An atomic GitHub action to download and install the Unity Editor for runners.",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)