2022-02-02 09:15:37 +00:00
|
|
|
import { BuildParameters } from '..';
|
|
|
|
import { getUnityChangeset } from 'unity-changeset';
|
2023-02-14 05:07:10 +00:00
|
|
|
import { exec, getExecOutput } from '@actions/exec';
|
|
|
|
import { restoreCache, saveCache } from '@actions/cache';
|
|
|
|
|
2022-02-02 09:15:37 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
class SetupMac {
|
2023-02-14 05:07:10 +00:00
|
|
|
static unityHubBasePath = `/Applications/"Unity Hub.app"`;
|
|
|
|
static unityHubExecPath = `${SetupMac.unityHubBasePath}/Contents/MacOS/"Unity Hub"`;
|
2022-02-02 09:15:37 +00:00
|
|
|
|
|
|
|
public static async setup(buildParameters: BuildParameters, actionFolder: string) {
|
2022-04-03 15:59:14 +00:00
|
|
|
const unityEditorPath = `/Applications/Unity/Hub/Editor/${buildParameters.editorVersion}/Unity.app/Contents/MacOS/Unity`;
|
2022-02-02 09:15:37 +00:00
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
if (!fs.existsSync(this.unityHubExecPath)) {
|
|
|
|
await SetupMac.installUnityHub(buildParameters);
|
2023-02-09 18:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync(unityEditorPath)) {
|
2022-02-02 09:15:37 +00:00
|
|
|
await SetupMac.installUnity(buildParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
await SetupMac.setEnvironmentVariables(buildParameters, actionFolder);
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
private static async installUnityHub(buildParameters, silent = false) {
|
|
|
|
// Can't use quotes in the cache package so we need a different path
|
|
|
|
const unityHubCachePath = `/Applications/Unity\\ Hub.app`;
|
|
|
|
|
|
|
|
const targetHubVersion =
|
|
|
|
buildParameters.unityHubVersionOnMac !== ''
|
|
|
|
? buildParameters.unityHubVersionOnMac
|
|
|
|
: await SetupMac.getLatestUnityHubVersion();
|
|
|
|
|
|
|
|
const restoreKey = `Cache-MacOS-UnityHub@${targetHubVersion}`;
|
|
|
|
|
|
|
|
if (buildParameters.cacheUnityInstallationOnMac) {
|
|
|
|
const cacheId = await restoreCache([unityHubCachePath], restoreKey);
|
|
|
|
if (cacheId) {
|
|
|
|
// Cache restored successfully, unity hub is installed now
|
|
|
|
return;
|
2022-02-02 09:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-14 05:07:10 +00:00
|
|
|
|
|
|
|
const commandSuffix = buildParameters.unityHubVersionOnMac !== '' ? `@${buildParameters.unityHubVersionOnMac}` : '';
|
|
|
|
const command = `brew install unity-hub${commandSuffix}`;
|
|
|
|
|
|
|
|
// Ignoring return code because the log seems to overflow the internal buffer which triggers
|
|
|
|
// a false error
|
|
|
|
const errorCode = await exec(command, undefined, { silent, ignoreReturnCode: true });
|
|
|
|
if (errorCode) {
|
|
|
|
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildParameters.cacheUnityInstallationOnMac) {
|
|
|
|
await saveCache([unityHubCachePath], restoreKey);
|
|
|
|
}
|
2022-02-02 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
/**
|
|
|
|
* Gets the latest version of Unity Hub available on brew
|
|
|
|
* @returns The latest version of Unity Hub available on brew
|
|
|
|
*/
|
|
|
|
private static async getLatestUnityHubVersion(): Promise<string> {
|
|
|
|
// Need to check if the latest version available is the same as the one we have cached
|
|
|
|
const hubVersionCommand = `/bin/bash -c "brew info unity-hub | grep -o '[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+'"`;
|
|
|
|
const result = await getExecOutput(hubVersionCommand, undefined, { silent: true });
|
|
|
|
if (result.exitCode === 0 && result.stdout !== '') {
|
|
|
|
return result.stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
2022-12-14 09:27:36 +00:00
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
private static getModuleParametersForTargetPlatform(targetPlatform: string): string {
|
|
|
|
let moduleArgument = '';
|
|
|
|
switch (targetPlatform) {
|
2022-12-14 09:27:36 +00:00
|
|
|
case 'iOS':
|
2023-02-14 05:07:10 +00:00
|
|
|
moduleArgument += `--module ios `;
|
2022-12-14 09:27:36 +00:00
|
|
|
break;
|
2023-02-09 18:24:15 +00:00
|
|
|
case 'tvOS':
|
2023-02-14 05:07:10 +00:00
|
|
|
moduleArgument += '--module tvos ';
|
2023-02-09 18:24:15 +00:00
|
|
|
break;
|
2022-12-14 09:27:36 +00:00
|
|
|
case 'StandaloneOSX':
|
2023-02-14 05:07:10 +00:00
|
|
|
moduleArgument += `--module mac-il2cpp `;
|
2022-12-14 09:27:36 +00:00
|
|
|
break;
|
2023-02-09 18:24:15 +00:00
|
|
|
case 'Android':
|
2023-02-14 05:07:10 +00:00
|
|
|
moduleArgument += `--module android `;
|
2022-12-14 09:27:36 +00:00
|
|
|
break;
|
2023-02-09 18:24:15 +00:00
|
|
|
case 'WebGL':
|
2023-02-14 05:07:10 +00:00
|
|
|
moduleArgument += '--module webgl ';
|
2023-02-09 18:24:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-02-14 05:07:10 +00:00
|
|
|
throw new Error(`Unsupported module for target platform: ${targetPlatform}.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return moduleArgument;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static async installUnity(buildParameters: BuildParameters, silent = false) {
|
|
|
|
const unityEditorPath = `/Applications/Unity/Hub/Editor/${buildParameters.editorVersion}`;
|
|
|
|
const key = `Cache-MacOS-UnityEditor-With-Module-${buildParameters.targetPlatform}@${buildParameters.editorVersion}`;
|
|
|
|
|
|
|
|
if (buildParameters.cacheUnityInstallationOnMac) {
|
|
|
|
const cacheId = await restoreCache([unityEditorPath], key);
|
|
|
|
if (cacheId) {
|
|
|
|
// Cache restored successfully, unity editor is installed now
|
|
|
|
return;
|
|
|
|
}
|
2022-12-14 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion);
|
|
|
|
const moduleArgument = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform);
|
|
|
|
|
|
|
|
const command = `${this.unityHubExecPath} -- --headless install \
|
|
|
|
--version ${buildParameters.editorVersion} \
|
|
|
|
--changeset ${unityChangeset.changeset} \
|
|
|
|
${moduleArgument} \
|
|
|
|
--childModules `;
|
2022-02-02 09:15:37 +00:00
|
|
|
|
|
|
|
// Ignoring return code because the log seems to overflow the internal buffer which triggers
|
|
|
|
// a false error
|
|
|
|
const errorCode = await exec(command, undefined, { silent, ignoreReturnCode: true });
|
|
|
|
if (errorCode) {
|
|
|
|
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
|
|
|
|
}
|
2023-02-14 05:07:10 +00:00
|
|
|
|
|
|
|
if (buildParameters.cacheUnityInstallationOnMac) {
|
|
|
|
await saveCache([unityEditorPath], key);
|
|
|
|
}
|
2022-02-02 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static async setEnvironmentVariables(buildParameters: BuildParameters, actionFolder: string) {
|
|
|
|
// Need to set environment variables from here because we execute
|
|
|
|
// the scripts on the host for mac
|
|
|
|
process.env.ACTION_FOLDER = actionFolder;
|
2022-04-03 15:59:14 +00:00
|
|
|
process.env.UNITY_VERSION = buildParameters.editorVersion;
|
2022-02-02 09:15:37 +00:00
|
|
|
process.env.UNITY_SERIAL = buildParameters.unitySerial;
|
2022-10-22 16:55:58 +00:00
|
|
|
process.env.UNITY_LICENSING_SERVER = buildParameters.unityLicensingServer;
|
2022-02-02 09:15:37 +00:00
|
|
|
process.env.PROJECT_PATH = buildParameters.projectPath;
|
2022-04-03 15:59:14 +00:00
|
|
|
process.env.BUILD_TARGET = buildParameters.targetPlatform;
|
2022-02-02 09:15:37 +00:00
|
|
|
process.env.BUILD_NAME = buildParameters.buildName;
|
|
|
|
process.env.BUILD_PATH = buildParameters.buildPath;
|
|
|
|
process.env.BUILD_FILE = buildParameters.buildFile;
|
|
|
|
process.env.BUILD_METHOD = buildParameters.buildMethod;
|
|
|
|
process.env.VERSION = buildParameters.buildVersion;
|
|
|
|
process.env.ANDROID_VERSION_CODE = buildParameters.androidVersionCode;
|
|
|
|
process.env.ANDROID_KEYSTORE_NAME = buildParameters.androidKeystoreName;
|
|
|
|
process.env.ANDROID_KEYSTORE_BASE64 = buildParameters.androidKeystoreBase64;
|
|
|
|
process.env.ANDROID_KEYSTORE_PASS = buildParameters.androidKeystorePass;
|
|
|
|
process.env.ANDROID_KEYALIAS_NAME = buildParameters.androidKeyaliasName;
|
|
|
|
process.env.ANDROID_KEYALIAS_PASS = buildParameters.androidKeyaliasPass;
|
|
|
|
process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion;
|
|
|
|
process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters;
|
2023-02-14 05:07:10 +00:00
|
|
|
process.env.ANDROID_EXPORT_TYPE = buildParameters.androidExportType;
|
|
|
|
process.env.ANDROID_SYMBOL_TYPE = buildParameters.androidSymbolType;
|
2022-02-02 09:15:37 +00:00
|
|
|
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
|
|
|
|
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SetupMac;
|