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

Commit

Permalink
Browse files Browse the repository at this point in the history
- misc cleanup
- better macos installation support
  • Loading branch information
StephenHodgson authored Jul 18, 2024
1 parent 75bee72 commit 8a66fa7
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
- os: ubuntu-latest
build-targets: 'StandaloneLinux64 Android iOS'
- os: windows-latest
build-targets: 'StandaloneWindows64 Android iOS'
- os: macos-14
build-targets: 'StandaloneOSX Android iOS VisionOS'
build-targets: 'StandaloneWindows64 Android WSAPlayer'
- os: macos-13
build-targets: 'StandaloneOSX iOS'
- os: macos-latest
build-targets: 'StandaloneOSX Android iOS'
build-targets: 'StandaloneOSX iOS VisionOS'

steps:
- name: checkout self
Expand Down
16 changes: 5 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28088,8 +28088,8 @@ const main = async () => {
core.debug(`buildTargets: ${buildTargets}`);

if (!buildTargets) {
modules = core.getInput('modules');
var modules = modules.replace(/,/g, '').split(/\s+/);
modules = core.getInput('modules');
var modules = modules.replace(/,/g, '').split(/\s+/);
} else {
const osType = os.type();
var moduleMap = undefined;
Expand Down Expand Up @@ -28169,15 +28169,9 @@ const main = async () => {

var pwsh = await io.which("pwsh", true);
var install = __nccwpck_require__.ab + "unity-install.ps1";
var exitCode = 0;

exitCode = await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`);

if (exitCode != 0) {
throw Error(`Unity Installation Failed! exitCode: ${exitCode}`)
}
await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`);
} catch (error) {
core.setFailed(error.message);
core.setFailed(`Unity Installation Failed! ${error.message}`);
}
}

Expand All @@ -28199,7 +28193,7 @@ const findFile = async (dir, filePath) => {
}

if (matchedFiles.length == 0) {
for(const subDir of directories) {
for (const subDir of directories) {
const nestedMatches = await findFile(subDir, filePath);

for (const nestedMatch of nestedMatches) {
Expand Down
67 changes: 44 additions & 23 deletions dist/unity-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ([String]::IsNullOrEmpty($unityVersion)) {
}

$projectPath = (Get-Item $versionFilePath).Directory.Parent.FullName
$projectPath = $projectPath -replace '\\','/'
$projectPath = $projectPath -replace '\\', '/'
Write-Host "Unity project path: `"$projectPath`""
"UNITY_PROJECT_PATH=$projectPath" >> $env:GITHUB_ENV
}
Expand All @@ -27,7 +27,8 @@ if ([String]::IsNullOrEmpty($unityVersion)) {
$vMatches = [regex]::Matches($version, $pattern)
$unityVersion = $vMatches[1].Groups['version'].Value.Trim()
$unityVersionChangeSet = $vMatches[2].Groups['revision'].Value.Trim()
} else {
}
else {
$version = $unityVersion
$unityVersionChangeSet = $version -replace '.*\((.*)\)', '$1'
$unityVersion = $version -replace '\s*\(.*\)', ''
Expand All @@ -37,7 +38,8 @@ if (-not ([String]::IsNullOrEmpty($unityVersion))) {
Write-Host ""
"UNITY_EDITOR_VERSION=$unityVersion" >> $env:GITHUB_ENV
Write-Host "Unity Editor version set to: $unityVersion"
} else {
}
else {
Write-Error "Failed to determine editor version to install!"
exit 1
}
Expand All @@ -53,11 +55,12 @@ if ($IsWindows) {

#. 'C:/Program Files/Unity Hub/Unity Hub.exe' -- --headless help
function Invoke-UnityHub {
$argList = (@('--','--headless') + $args.Split(" "))
$argList = (@('--', '--headless') + $args.Split(" "))
$p = Start-Process -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList $argList
$p.WaitForExit()
}
} elseif ($IsMacOS) {
}
elseif ($IsMacOS) {
$hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
$editorRootPath = "/Applications/Unity/Hub/Editor/"
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
Expand All @@ -68,11 +71,12 @@ if ($IsWindows) {

#. "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless help
function Invoke-UnityHub {
$argList = (@('--','--headless') + $args.Split(" "))
$argList = (@('--', '--headless') + $args.Split(" "))
$p = Start-Process -NoNewWindow -PassThru -Wait -FilePath "$hubPath" -ArgumentList $argList
$p.WaitForExit()
}
} elseif ($IsLinux) {
}
elseif ($IsLinux) {
$hubPath = "/usr/bin/unityhub"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
Expand All @@ -86,7 +90,8 @@ if ($IsWindows) {
$argsList = $args.Split(" ")
xvfb-run --auto-servernum "$hubPath" --disable-gpu-sandbox --headless $argsList
}
} else {
}
else {
Write-Error "Unsupported platform: $($global:PSVersionTable.Platform)"
exit 1
}
Expand Down Expand Up @@ -115,7 +120,8 @@ if ( -not (Test-Path -Path "$hubPath") ) {
Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)"
exit 1
}
} elseif ($IsMacOS) {
}
elseif ($IsMacOS) {
Write-Host "::group::Installing Unity Hub on macOS..."
$package = "UnityHubSetup.dmg"
$downloadPath = "$outPath/$package"
Expand Down Expand Up @@ -146,17 +152,28 @@ if ( -not (Test-Path -Path "$hubPath") ) {

sudo cp -rf $dmgAppPath "/Applications"
hdiutil unmount $dmgVolume

if (!(Test-Path $hubPath)) {
Write-Error "Failed to install Unity Hub"
exit 1
}

Write-Host "Unity Hub installed at `"$hubPath`""

sudo chmod -R 777 $hubPath
sudo mkdir -p "/Library/Application Support/Unity"
sudo chmod 775 "/Library/Application Support/Unity"
touch '/Library/Application Support/Unity/temp'
} elseif ($IsLinux) {
sudo chmod -R 777 "/Library/Application Support/Unity"
}
elseif ($IsLinux) {
Write-Host "::group::Installing Unity Hub on ubuntu..."
sudo sh -c 'echo ""deb https://hub.unity3d.com/linux/repos/deb stable main"" > /etc/apt/sources.list.d/unityhub.list'
wget -qO - https://hub.unity3d.com/linux/keys/public | sudo apt-key add -
sudo apt update
sudo apt install -y unityhub
$hubPath = which unityhub
} else {
sudo chmod -R 777 $hubPath
}
else {
Write-Error "Unsupported platform: $($global:PSVersionTable.Platform)"
exit 1
}
Expand All @@ -181,7 +198,7 @@ Write-Host "::endgroup::"
#}

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

# if architecture is set, check if the specific architecture is installed
if (-not [string]::IsNullOrEmpty($architecture)) {
Expand All @@ -192,12 +209,15 @@ if (-not [string]::IsNullOrEmpty($architecture)) {

# iterate over the editors and check if the version name contains (Intel) for x86_64 or (Apple silicon) for arm64
foreach ($archEditor in $archEditors) {
Write-Host "::debug::$archEditor"

if ($IsMacOS) {
if ((($archEditor.Contains("(Intel)") -and $architecture -eq 'x86_64')) -or ($archEditor.Contains("(Apple silicon)") -and $architecture -eq 'arm64')) {
# set the editor path based on the editor string that was found using a substring. Split subtring by ',' and take the last element
$editorPath = $archEditor.Substring(0, $archEditor.IndexOf(','))
}
} else {
}
else {
Write-Error "Architecture lookup not supported for $($global:PSVersionTable.Platform)"
exit 1
}
Expand Down Expand Up @@ -242,17 +262,18 @@ function AddModules {

if (-not (Test-Path -Path $editorPath)) {
Write-Host "Installing $unityVersion ($unityVersionChangeSet)"
$installArgs = @('install',"--version $unityVersion","--changeset $unityVersionChangeSet",'--cm')
$installArgs = @('install', "--version $unityVersion", "--changeset $unityVersionChangeSet", '--cm')
$installModules = AddModules

if (-not [string]::IsNullOrEmpty($architecture)) {
$installArgs += "-a $architecture"
}

Invoke-Hub-Install $installModules $installArgs
} else {
}
else {
Write-Host "Checking modules for $unityVersion ($unityVersionChangeSet)"
$installArgs = @('install-modules',"--version $unityVersion",'--cm')
$installArgs = @('install-modules', "--version $unityVersion", '--cm')
$installModules = AddModules

if ($installModules.Count -gt 0) {
Expand All @@ -264,14 +285,14 @@ Write-Host "Installed Editors:"
Invoke-UnityHub editors -i

if (-not (Test-Path -Path $editorPath)) {
Write-Error "Failed to validate installed editor path at $editorPath"
Write-Error "Failed to validate installed editor path at `"$editorPath`""
exit 1
}

$modulesPath = '{0}{1}/modules.json' -f $editorRootPath,$UnityVersion
$modulesPath = '{0}{1}/modules.json' -f $editorRootPath, $UnityVersion

if (-not (Test-Path -Path $modulesPath)) {
$editorPath = "{0}{1}" -f $editorRootPath,$unityVersion
$editorPath = "{0}{1}" -f $editorRootPath, $unityVersion
Write-Error "Failed to resolve modules path at $modulesPath"

if (Test-Path -Path $editorPath) {
Expand All @@ -295,9 +316,9 @@ $envEditorPath = $env:UNITY_EDITOR_PATH

if ([String]::IsNullOrEmpty($envEditorPath)) {
Write-Host ""
$editorPath = $editorPath -replace '\\','/'
$editorPath = $editorPath -replace '\\', '/'
"UNITY_EDITOR_PATH=$editorPath" >> $env:GITHUB_ENV
Write-Host "UnityEditor path set to: $editorPath"
Write-Host "UnityEditor path set to: `"$editorPath`""
}

exit 0
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-setup",
"version": "7.5.2",
"version": "7.5.3",
"description": "An atomic GitHub action to download and install the Unity Editor for runners.",
"main": "src/index.js",
"scripts": {
Expand Down
16 changes: 5 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const main = async () => {
core.debug(`buildTargets: ${buildTargets}`);

if (!buildTargets) {
modules = core.getInput('modules');
var modules = modules.replace(/,/g, '').split(/\s+/);
modules = core.getInput('modules');
var modules = modules.replace(/,/g, '').split(/\s+/);
} else {
const osType = os.type();
var moduleMap = undefined;
Expand Down Expand Up @@ -108,15 +108,9 @@ const main = async () => {

var pwsh = await io.which("pwsh", true);
var install = path.resolve(__dirname, 'unity-install.ps1');
var exitCode = 0;

exitCode = await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`);

if (exitCode != 0) {
throw Error(`Unity Installation Failed! exitCode: ${exitCode}`)
}
await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`);
} catch (error) {
core.setFailed(error.message);
core.setFailed(`Unity Installation Failed! ${error.message}`);
}
}

Expand All @@ -138,7 +132,7 @@ const findFile = async (dir, filePath) => {
}

if (matchedFiles.length == 0) {
for(const subDir of directories) {
for (const subDir of directories) {
const nestedMatches = await findFile(subDir, filePath);

for (const nestedMatch of nestedMatches) {
Expand Down
Loading

0 comments on commit 8a66fa7

Please sign in to comment.