This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
226 lines (186 loc) · 8.71 KB
/
action.yml
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
name: 'Unity Validate (XRTK)'
description: 'Validates the Unity editor installation and project'
inputs:
modules:
description: 'additional modules to install with the editor (i.e "webgl android lumin")'
required: false
default: ''
version-file-path:
description: 'Optional, specify a path to search for the unity project version text file. Use this if validation fails to find a valid project version file.'
required: false
default: '**/ProjectSettings/ProjectVersion.txt'
outputs:
editor-path:
description: 'The path to the Unity Editor'
value: ${{ steps.validate.outputs.editor-path }}
project-path:
description: 'The path to the unity project'
value: ${{ steps.validate.outputs.project-path }}
runs:
using: "composite"
steps:
- id: validate
name: 'Unity Editor Validation'
run: |
# Unity Editor Validation
Write-Host "::group::Unity Editor Validation"
$versionFile = "${{ inputs.version-file-path }}"
$modulesString = "${{ inputs.modules }}"
$modules = $modulesString.Split(" ")
if ( -not (Test-Path -Path $versionFile) ) {
Write-Error "Failed to find a valid project version file at `"$versionFile`""
exit 1
}
$projectPath = (Get-Item $versionFile).Directory.Parent.FullName
Write-Host "Unity project path: `"$projectPath`""
"project-path=$projectPath" >> $env:GITHUB_ENV
$version = Get-Content $versionFile
$pattern = '(?<version>(?:(?<major>\d+)\.)?(?:(?<minor>\d+)\.)?(?:(?<patch>\d+[fab]\d+)\b))|((?:\((?<revision>\w+))\))'
$matches = $matches = [regex]::Matches($version, $pattern)
$unityVersion = $matches[1].Groups['version'].Value.Trim()
$unityVersionChangeSet = $matches[2].Groups['revision'].Value.Trim()
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', 'lumin', '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', 'lumin', 'webgl', 'android')
}
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
#. "/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(" ")
}
}
# Install hub if not found
if ( -not (Test-Path -Path "$hubPath") ) {
Write-Host "$(Get-Date): Downloading Unity Hub..."
$baseUrl = "https://public-cdn.cloud.unity3d.com/hub/prod";
$outPath = $PSScriptRoot
$wc = New-Object System.Net.WebClient
Write-Host "$(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
Write-Host $dmgVolume
$dmgAppPath = (find "$DMGVolume" -name "*.app" -depth 1)
Write-Host $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
}
Write-Host "Unity Hub found at `"$hubPath`""
Write-Host ""
Write-Host "Editor root path currently set to: `"$editorRootPath`""
Write-Host ""
unity-hub help
Write-Host ""
$editorPath = "{0}{1}{2}" -f $editorRootPath,$unityVersion,$editorFileEx
if ( -not (Test-Path -Path $editorPath)) {
Write-Host "Installing $unityVersion ($unityVersionChangeSet)..."
$installArgs = @('install',"--version $unityVersion","--changeset $unityVersionChangeSet",'--cm')
$addModules = @()
foreach ($module in $modules ) {
if ( $module -eq 'android' ) {
$addmodules += 'android-open-jdk'
$addmodules += 'android-sdk-ndk-tools'
}
}
$modules += $addModules
foreach ( $module in $modules ) {
$installArgs += '-m'
$installArgs += $module
Write-Host " with module: $module"
}
$installArgsString = $installArgs -join " "
unity-hub $installArgsString
}
Write-Host ""
unity-hub editors -i
Write-Host ""
if ( -not (Test-Path -Path $editorPath) ) {
Write-Error "Failed to validate installed editor path at $editorPath"
exit 1
}
$modulesPath = '{0}{1}{2}modules.json' -f $editorRootPath,$UnityVersion,[IO.Path]::DirectorySeparatorChar
if ( -not (Test-Path -Path $modulesPath)) {
$editorPath = "{0}{1}" -f $editorRootPath,$unityVersion
Write-Host "Cleaning up invalid installation under $editorPath"
Write-Error "Failed to resolve modules path at $modulesPath"
if (Test-Path -Path $editorPath) {
ls $editorPath
# Remove-Item $editorPath -Recurse -Force
}
exit 1
}
Write-Host "Modules Manifest: "$modulesPath
Write-Host ""
foreach ($module in (Get-Content -Raw -Path $modulesPath | ConvertFrom-Json -AsHashTable)) {
if ( ($module.category -eq 'Platforms') -and ($module.visible -eq $true) ) {
if ( -not ($modules -contains $module.id) ) {
Write-Host "additional module option: " $module.id
}
}
}
Write-Host ""
Write-Host "UnityEditor path set to: $editorPath"
"editor-path=$editorPath" >> $env:GITHUB_ENV
Write-Host "::endgroup::"
exit 0
shell: pwsh