@@ -3533,7 +3533,7 @@ class LicensingClient {
35333533 await fs.promises.access(this.unityHub.rootDirectory, fs.constants.R_OK);
35343534 }
35353535 catch (error) {
3536- await this.unityHub.Install( );
3536+ throw new Error('Unity Hub is not installed or not accessible. Please install Unity Hub before using the Licensing Client.' );
35373537 }
35383538 const licensingClientExecutable = process.platform === 'win32' ? 'Unity.Licensing.Client.exe' : 'Unity.Licensing.Client';
35393539 const licenseClientPath = await (0, utilities_1.ResolveGlobToPath)([this.unityHub.rootDirectory, '**', licensingClientExecutable]);
@@ -4235,6 +4235,14 @@ class UnityEditor {
42354235 this.version = version;
42364236 }
42374237 this.autoAddNoGraphics = this.version.isGreaterThan('2018.0.0');
4238+ // check if we have permissions to write to this file
4239+ try {
4240+ fs.accessSync(this.editorRootPath, fs.constants.W_OK);
4241+ }
4242+ catch (error) {
4243+ return;
4244+ }
4245+ // ensure metadata.hub.json exists and has a productName entry
42384246 const hubMetaDataPath = path.join(this.editorRootPath, 'metadata.hub.json');
42394247 if (!fs.existsSync(hubMetaDataPath)) {
42404248 const metadata = {
@@ -4843,48 +4851,66 @@ class UnityHub {
48434851 * @param autoUpdate If true, automatically updates the Unity Hub if it is already installed. Default is true.
48444852 * @returns The path to the Unity Hub executable.
48454853 */
4846- async Install(autoUpdate = true) {
4854+ async Install(autoUpdate = true, version) {
4855+ if (autoUpdate && version) {
4856+ throw new Error('Cannot use autoUpdate with version.');
4857+ }
48474858 let isInstalled = false;
48484859 try {
48494860 await fs.promises.access(this.executable, fs.constants.X_OK);
48504861 isInstalled = true;
48514862 }
48524863 catch {
4853- await this.installHub();
4864+ await this.installHub(version );
48544865 }
48554866 if (isInstalled && autoUpdate) {
48564867 const installedVersion = await this.getInstalledHubVersion();
48574868 this.logger.ci(`Installed Unity Hub version: ${installedVersion.version}`);
4858- let latestVersion = undefined;
4859- try {
4860- latestVersion = await this.getLatestHubVersion();
4861- this.logger.ci(`Latest Unity Hub version: ${latestVersion.version}`);
4869+ let versionToInstall = null;
4870+ if (!version) {
4871+ try {
4872+ versionToInstall = await this.getLatestHubVersion();
4873+ this.logger.ci(`Latest Unity Hub version: ${versionToInstall.version}`);
4874+ }
4875+ catch (error) {
4876+ this.logger.warn(`Failed to get latest Unity Hub version: ${error}`);
4877+ }
48624878 }
4863- catch (error) {
4864- this.logger.warn(`Failed to get latest Unity Hub version: ${error}`);
4879+ else {
4880+ versionToInstall = (0, semver_1.coerce)(version);
4881+ }
4882+ if (versionToInstall === null ||
4883+ !versionToInstall &&
4884+ !(0, semver_1.valid)(versionToInstall)) {
4885+ throw new Error(`Invalid Unity Hub version to install: ${versionToInstall}`);
48654886 }
4866- if (latestVersion && (0, semver_1.compare)(installedVersion, latestVersion) < 0) {
4867- this.logger.info(`Updating Unity Hub from ${installedVersion.version} to ${latestVersion.version}...`);
4887+ const mustInstall = version || (versionToInstall && (0, semver_1.compare)(installedVersion, versionToInstall) < 0);
4888+ if (mustInstall) {
4889+ this.logger.info(`Updating Unity Hub from ${installedVersion.version} to ${versionToInstall.version}...`);
48684890 if (process.platform === 'darwin') {
48694891 await (0, utilities_1.Exec)('sudo', ['rm', '-rf', this.rootDirectory], { silent: true, showCommand: true });
4870- await this.installHub();
4892+ await this.installHub(version );
48714893 }
48724894 else if (process.platform === 'win32') {
4873- const uninstaller = path.join(path.dirname( this.executable) , 'Uninstall Unity Hub.exe');
4895+ const uninstaller = path.join(this.rootDirectory , 'Uninstall Unity Hub.exe');
48744896 await (0, utilities_1.Exec)('powershell', [
48754897 '-NoProfile',
48764898 '-Command',
48774899 `Start-Process -FilePath '${uninstaller}' -ArgumentList '/S' -Verb RunAs -Wait`
48784900 ], { silent: true, showCommand: true });
4879- await this.installHub();
4901+ await (0, utilities_1.DeleteDirectory)(this.rootDirectory);
4902+ await this.installHub(version);
48804903 }
48814904 else if (process.platform === 'linux') {
48824905 await (0, utilities_1.Exec)('sudo', ['sh', '-c', `#!/bin/bash
48834906set -e
48844907wget -qO - https://hub.unity3d.com/linux/keys/public | gpg --dearmor | sudo tee /usr/share/keyrings/Unity_Technologies_ApS.gpg >/dev/null
48854908sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/Unity_Technologies_ApS.gpg] https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list'
48864909sudo apt-get update --allow-releaseinfo-change
4887- sudo apt-get install -y --no-install-recommends --only-upgrade unityhub`]);
4910+ sudo apt-get install -y --no-install-recommends --only-upgrade unityhub${version ? '=' + version : ''}`]);
4911+ }
4912+ else {
4913+ throw new Error(`Unsupported platform: ${process.platform}`);
48884914 }
48894915 }
48904916 else {
@@ -4894,11 +4920,19 @@ sudo apt-get install -y --no-install-recommends --only-upgrade unityhub`]);
48944920 await fs.promises.access(this.executable, fs.constants.X_OK);
48954921 return this.executable;
48964922 }
4897- async installHub() {
4898- this.logger.ci(`Installing Unity Hub...`);
4923+ async installHub(version) {
4924+ this.logger.ci(`Installing Unity Hub${version ? ' ' + version : ''}...`);
4925+ if (!version) {
4926+ switch (process.platform) {
4927+ case 'win32':
4928+ case 'darwin':
4929+ version = 'prod';
4930+ break;
4931+ }
4932+ }
48994933 switch (process.platform) {
49004934 case 'win32': {
4901- const url = ' https://public-cdn.cloud.unity3d.com/hub/prod /UnityHubSetup.exe' ;
4935+ const url = ` https://public-cdn.cloud.unity3d.com/hub/${version} /UnityHubSetup.exe` ;
49024936 const downloadPath = path.join((0, utilities_1.GetTempDir)(), 'UnityHubSetup.exe');
49034937 await (0, utilities_1.DownloadFile)(url, downloadPath);
49044938 this.logger.info(`Running Unity Hub installer...`);
@@ -4917,7 +4951,7 @@ sudo apt-get install -y --no-install-recommends --only-upgrade unityhub`]);
49174951 break;
49184952 }
49194953 case 'darwin': {
4920- const baseUrl = ' https://public-cdn.cloud.unity3d.com/hub/prod' ;
4954+ const baseUrl = ` https://public-cdn.cloud.unity3d.com/hub/${version}` ;
49214955 const url = `${baseUrl}/UnityHubSetup-${process.arch}.dmg`;
49224956 const downloadPath = path.join((0, utilities_1.GetTempDir)(), `UnityHubSetup-${process.arch}.dmg`);
49234957 await (0, utilities_1.DownloadFile)(url, downloadPath);
@@ -4966,11 +5000,12 @@ wget -qO - https://hub.unity3d.com/linux/keys/public | gpg --dearmor | tee /usr/
49665000echo "deb [signed-by=/usr/share/keyrings/Unity_Technologies_ApS.gpg] https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list
49675001echo "deb https://archive.ubuntu.com/ubuntu jammy main universe" | tee /etc/apt/sources.list.d/jammy.list
49685002apt-get update
4969- apt-get install -y --no-install-recommends unityhub ffmpeg libgtk2.0-0 libglu1-mesa libgconf-2-4 libncurses5
5003+ apt-get install -y --no-install-recommends unityhub${version ? '=' + version : ''} ffmpeg libgtk2.0-0 libglu1-mesa libgconf-2-4 libncurses5
49705004apt-get clean
49715005sed -i 's/^\\(.*DISPLAY=:.*XAUTHORITY=.*\\)\\( "\\$@" \\)2>&1$/\\1\\2/' /usr/bin/xvfb-run
49725006printf '#!/bin/bash\nxvfb-run --auto-servernum /opt/unityhub/unityhub "$@" 2>/dev/null' | tee /usr/bin/unity-hub >/dev/null
49735007chmod 777 /usr/bin/unity-hub
5008+ which unityhub || { echo "Unity Hub installation failed"; exit 1; }
49745009hubPath=$(which unityhub)
49755010
49765011if [ -z "$hubPath" ]; then
@@ -4985,7 +5020,8 @@ chmod -R 777 "$hubPath"`]);
49855020 throw new Error(`Unsupported platform: ${process.platform}`);
49865021 }
49875022 await fs.promises.access(this.executable, fs.constants.X_OK);
4988- this.logger.debug(`Unity Hub install complete`);
5023+ const installedVersion = await this.getInstalledHubVersion();
5024+ this.logger.info(`Unity Hub ${installedVersion} installed successfully.`);
49895025 }
49905026 async getInstalledHubVersion() {
49915027 let asarPath = undefined;
@@ -5005,8 +5041,15 @@ chmod -R 777 "$hubPath"`]);
50055041 catch {
50065042 throw new Error('Unity Hub is not installed.');
50075043 }
5008- const fileBuffer = asar.extractFile(asarPath, 'package.json');
5009- const packageJson = JSON.parse(fileBuffer.toString());
5044+ asar.uncacheAll();
5045+ const fileBuffer = asar.extractFile(asarPath, 'package.json').toString('utf-8');
5046+ let packageJson;
5047+ try {
5048+ packageJson = JSON.parse(fileBuffer);
5049+ }
5050+ catch (error) {
5051+ throw new Error(`Failed to parse Unity Hub package.json: ${error}\n${fileBuffer}`);
5052+ }
50105053 const version = (0, semver_1.coerce)(packageJson.version);
50115054 if (!version || !(0, semver_1.valid)(version)) {
50125055 throw new Error(`Failed to parse Unity Hub version: ${packageJson.version}`);
@@ -6259,7 +6302,7 @@ async function Exec(command, args, options = { silent: false, showCommand: true
62596302 }
62606303 }
62616304 if (exitCode !== 0) {
6262- throw new Error(`${command} failed with exit code ${exitCode}`);
6305+ throw new Error(`${command} failed with exit code ${exitCode}\n${output} `);
62636306 }
62646307 }
62656308 return output;
@@ -63443,8 +63486,12 @@ async function main() {
6344363486 core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
6344463487 }
6344563488 const autoUpdate = core.getInput('auto-update-hub');
63489+ const hubVersion = core.getInput('hub-version');
63490+ if (autoUpdate === 'true' && hubVersion && hubVersion.length > 0) {
63491+ throw new Error('Cannot specify a specific Unity Hub version when auto-update is set to true.');
63492+ }
6344663493 const unityHub = new unity_cli_1.UnityHub();
63447- const unityHubPath = await unityHub.Install(autoUpdate === 'true');
63494+ const unityHubPath = await unityHub.Install(autoUpdate === 'true', hubVersion );
6344863495 if (!unityHubPath || unityHubPath.length === 0) {
6344963496 throw new Error('Failed to install or locate Unity Hub!');
6345063497 }
0 commit comments