2022-02-02 09:15:37 +00:00
|
|
|
import { BuildParameters } from '..';
|
|
|
|
import { getUnityChangeset } from 'unity-changeset';
|
|
|
|
import { exec } from '@actions/exec';
|
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
class SetupMac {
|
|
|
|
static unityHubPath = `"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"`;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Only install unity if the editor doesn't already exist
|
|
|
|
if (!fs.existsSync(unityEditorPath)) {
|
|
|
|
await SetupMac.installUnityHub();
|
|
|
|
await SetupMac.installUnity(buildParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
await SetupMac.setEnvironmentVariables(buildParameters, actionFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static async installUnityHub(silent = false) {
|
|
|
|
const command = 'brew install unity-hub';
|
|
|
|
if (!fs.existsSync(this.unityHubPath)) {
|
|
|
|
// 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.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static async installUnity(buildParameters: BuildParameters, silent = false) {
|
2022-04-03 15:59:14 +00:00
|
|
|
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion);
|
2022-02-02 09:15:37 +00:00
|
|
|
const command = `${this.unityHubPath} -- --headless install \
|
2022-04-03 15:59:14 +00:00
|
|
|
--version ${buildParameters.editorVersion} \
|
2022-02-02 09:15:37 +00:00
|
|
|
--changeset ${unityChangeset.changeset} \
|
|
|
|
--module mac-il2cpp \
|
|
|
|
--childModules`;
|
|
|
|
|
|
|
|
// 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.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
|
|
|
|
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SetupMac;
|