Misc QOL Updates and bug fixes (#505)
* Add caching for Unity Hub/Editor on MacOS. Add parameter to pin Unity Hub version on MacOS. Live output MacOS build log to console. Hid extraneous log outputs from git. Throw error when failures detected in log output. * Update pr template links * Add system to build Android Project. Update PR Template links. Fix missing types on functions. Cleanup mac-setup module installation * Switch to androidExportType instead of exportGoogleAndroidProject * Enforce minimum node version * Enforce node version minimum. Added yarn-audit-fix to dev dependencies and Updated package vulnerabilities. * Improve deprecation warning * Add android symbol type parameter. Change windows scripts to use $LastExitCode and not $?. Update tests. * Fix issues on android symbols for older unity versions. Change symbol default to public. Increase build test coverage of unity versions. * Remove 2018.1 from tests * Remove out variable declaration to support Unity 2018 in default build script. Remove <2019.3 versions of unity from windows builder as IL2CPP isn't supported until 2019.3. * Fix typo. Use reflection to set buildAppBundle as Unity 2018.2 doesn't support it * Add missing reflection using * Remove 2018-2019.3 unity versions from mac as they don't support IL2CPP. Fix app identifier for android in testproject * Fix android bundle id * Updated android identifier. Removed incompatible unity versions from tests. Add retry logic to windows as it seems to have licensing issues when so many runners start * Add timeout and continue on error
This commit is contained in:
@@ -95,34 +95,41 @@ describe('BuildParameters', () => {
|
||||
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildFile: mockValue }));
|
||||
});
|
||||
|
||||
test.each([Platform.types.StandaloneWindows, Platform.types.StandaloneWindows64])(
|
||||
'appends exe for %s',
|
||||
async (targetPlatform) => {
|
||||
test.each`
|
||||
targetPlatform | expectedExtension | androidExportType
|
||||
${Platform.types.Android} | ${'.apk'} | ${'androidPackage'}
|
||||
${Platform.types.Android} | ${'.aab'} | ${'androidAppBundle'}
|
||||
${Platform.types.Android} | ${''} | ${'androidStudioProject'}
|
||||
${Platform.types.StandaloneWindows} | ${'.exe'} | ${'n/a'}
|
||||
${Platform.types.StandaloneWindows64} | ${'.exe'} | ${'n/a'}
|
||||
`(
|
||||
'appends $expectedExtension for $targetPlatform with androidExportType $androidExportType',
|
||||
async ({ targetPlatform, expectedExtension, androidExportType }) => {
|
||||
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue(androidExportType);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(
|
||||
expect.objectContaining({ buildFile: `${targetPlatform}.exe` }),
|
||||
expect.objectContaining({ buildFile: `${targetPlatform}${expectedExtension}` }),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.each([Platform.types.Android])('appends apk for %s', async (targetPlatform) => {
|
||||
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'androidAppBundle', 'get').mockReturnValue(false);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(
|
||||
expect.objectContaining({ buildFile: `${targetPlatform}.apk` }),
|
||||
);
|
||||
});
|
||||
|
||||
test.each([Platform.types.Android])('appends aab for %s', async (targetPlatform) => {
|
||||
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'androidAppBundle', 'get').mockReturnValue(true);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(
|
||||
expect.objectContaining({ buildFile: `${targetPlatform}.aab` }),
|
||||
);
|
||||
});
|
||||
test.each`
|
||||
targetPlatform | androidSymbolType
|
||||
${Platform.types.Android} | ${'none'}
|
||||
${Platform.types.Android} | ${'public'}
|
||||
${Platform.types.Android} | ${'debugging'}
|
||||
${Platform.types.StandaloneWindows} | ${'none'}
|
||||
${Platform.types.StandaloneWindows64} | ${'none'}
|
||||
`(
|
||||
'androidSymbolType is set to $androidSymbolType when targetPlatform is $targetPlatform and input targetSymbolType is $androidSymbolType',
|
||||
async ({ targetPlatform, androidSymbolType }) => {
|
||||
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
|
||||
jest.spyOn(Input, 'androidSymbolType', 'get').mockReturnValue(androidSymbolType);
|
||||
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ androidSymbolType }));
|
||||
},
|
||||
);
|
||||
|
||||
it('returns the build method', async () => {
|
||||
const mockValue = 'Namespace.ClassName.BuildMethod';
|
||||
|
||||
@@ -33,6 +33,9 @@ class BuildParameters {
|
||||
public androidKeyaliasPass!: string;
|
||||
public androidTargetSdkVersion!: string;
|
||||
public androidSdkManagerParameters!: string;
|
||||
public androidExportType!: string;
|
||||
public androidSymbolType!: string;
|
||||
|
||||
public customParameters!: string;
|
||||
public sshAgent!: string;
|
||||
public cloudRunnerCluster!: string;
|
||||
@@ -71,14 +74,30 @@ class BuildParameters {
|
||||
public garbageCollectionMaxAge!: number;
|
||||
public constantGarbageCollection!: boolean;
|
||||
public githubChecks!: boolean;
|
||||
public cacheUnityInstallationOnMac!: boolean;
|
||||
public unityHubVersionOnMac!: string;
|
||||
|
||||
static async create(): Promise<BuildParameters> {
|
||||
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidAppBundle);
|
||||
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidExportType);
|
||||
const editorVersion = UnityVersioning.determineUnityVersion(Input.projectPath, Input.unityVersion);
|
||||
const buildVersion = await Versioning.determineBuildVersion(Input.versioningStrategy, Input.specifiedVersion);
|
||||
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode);
|
||||
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion);
|
||||
|
||||
const androidSymbolExportType = Input.androidSymbolType;
|
||||
if (Platform.isAndroid(Input.targetPlatform)) {
|
||||
switch (androidSymbolExportType) {
|
||||
case 'none':
|
||||
case 'public':
|
||||
case 'debugging':
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Invalid androidSymbolType: ${Input.androidSymbolType}. Must be one of: none, public, debugging`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Todo - Don't use process.env directly, that's what the input model class is for.
|
||||
// ---
|
||||
let unitySerial = '';
|
||||
@@ -118,6 +137,8 @@ class BuildParameters {
|
||||
androidKeyaliasPass: Input.androidKeyaliasPass,
|
||||
androidTargetSdkVersion: Input.androidTargetSdkVersion,
|
||||
androidSdkManagerParameters,
|
||||
androidExportType: Input.androidExportType,
|
||||
androidSymbolType: androidSymbolExportType,
|
||||
customParameters: Input.customParameters,
|
||||
sshAgent: Input.sshAgent,
|
||||
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
|
||||
@@ -155,22 +176,35 @@ class BuildParameters {
|
||||
constantGarbageCollection: CloudRunnerOptions.constantGarbageCollection,
|
||||
garbageCollectionMaxAge: CloudRunnerOptions.garbageCollectionMaxAge,
|
||||
githubChecks: CloudRunnerOptions.githubChecks,
|
||||
cacheUnityInstallationOnMac: Input.cacheUnityInstallationOnMac,
|
||||
unityHubVersionOnMac: Input.unityHubVersionOnMac,
|
||||
};
|
||||
}
|
||||
|
||||
static parseBuildFile(filename, platform, androidAppBundle) {
|
||||
static parseBuildFile(filename: string, platform: string, androidExportType: string): string {
|
||||
if (Platform.isWindows(platform)) {
|
||||
return `${filename}.exe`;
|
||||
}
|
||||
|
||||
if (Platform.isAndroid(platform)) {
|
||||
return androidAppBundle ? `${filename}.aab` : `${filename}.apk`;
|
||||
switch (androidExportType) {
|
||||
case `androidPackage`:
|
||||
return `${filename}.apk`;
|
||||
case `androidAppBundle`:
|
||||
return `${filename}.aab`;
|
||||
case `androidStudioProject`:
|
||||
return filename;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown Android Export Type: ${androidExportType}. Must be one of androidPackage for apk, androidAppBundle for aab, androidStudioProject for android project`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
static getSerialFromLicenseFile(license) {
|
||||
static getSerialFromLicenseFile(license: string) {
|
||||
const startKey = `<DeveloperData Value="`;
|
||||
const endKey = `"/>`;
|
||||
const startIndex = license.indexOf(startKey) + startKey.length;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { exec } from '@actions/exec';
|
||||
import { execWithErrorCheck } from './exec-with-error-check';
|
||||
import ImageEnvironmentFactory from './image-environment-factory';
|
||||
import { existsSync, mkdirSync } from 'fs';
|
||||
import path from 'path';
|
||||
@@ -23,9 +23,9 @@ class Docker {
|
||||
}
|
||||
if (options !== false) {
|
||||
options.silent = silent;
|
||||
await exec(runCommand, undefined, options);
|
||||
await execWithErrorCheck(runCommand, undefined, options);
|
||||
} else {
|
||||
await exec(runCommand, undefined, { silent });
|
||||
await execWithErrorCheck(runCommand, undefined, { silent });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
src/model/exec-with-error-check.ts
Normal file
24
src/model/exec-with-error-check.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { getExecOutput, ExecOptions } from '@actions/exec';
|
||||
|
||||
export async function execWithErrorCheck(
|
||||
commandLine: string,
|
||||
arguments_?: string[],
|
||||
options?: ExecOptions,
|
||||
): Promise<number> {
|
||||
const result = await getExecOutput(commandLine, arguments_, options);
|
||||
|
||||
// Check for errors in the Build Results section
|
||||
const match = result.stdout.match(/^#\s*Build results\s*#(.*)^Size:/ms);
|
||||
|
||||
if (match) {
|
||||
const buildResults = match[1];
|
||||
const errorMatch = buildResults.match(/^Errors:\s*(\d+)$/m);
|
||||
if (errorMatch && Number.parseInt(errorMatch[1], 10) !== 0) {
|
||||
throw new Error(`There was an error building the project. Please read the logs for details.`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`There was an error building the project. Please read the logs for details.`);
|
||||
}
|
||||
|
||||
return result.exitCode;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ class Parameter {
|
||||
}
|
||||
|
||||
class ImageEnvironmentFactory {
|
||||
public static getEnvVarString(parameters, additionalVariables: any[] = []) {
|
||||
public static getEnvVarString(parameters: BuildParameters, additionalVariables: any[] = []) {
|
||||
const environmentVariables = ImageEnvironmentFactory.getEnvironmentVariables(parameters, additionalVariables);
|
||||
let string = '';
|
||||
for (const p of environmentVariables) {
|
||||
@@ -50,6 +50,8 @@ class ImageEnvironmentFactory {
|
||||
{ name: 'ANDROID_KEYALIAS_PASS', value: parameters.androidKeyaliasPass },
|
||||
{ name: 'ANDROID_TARGET_SDK_VERSION', value: parameters.androidTargetSdkVersion },
|
||||
{ name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters },
|
||||
{ name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType },
|
||||
{ name: 'ANDROID_SYMBOL_TYPE', value: parameters.androidSymbolType },
|
||||
{ name: 'CUSTOM_PARAMETERS', value: parameters.customParameters },
|
||||
{ name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo },
|
||||
{ name: 'GITHUB_REF', value: process.env.GITHUB_REF },
|
||||
|
||||
@@ -161,6 +161,82 @@ describe('Input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('androidExportType', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.androidExportType).toStrictEqual('androidPackage');
|
||||
});
|
||||
|
||||
// TODO: Remove "and androidAppBundle is not set" in v3
|
||||
test.each`
|
||||
input | expected
|
||||
${'androidPackage'} | ${'androidPackage'}
|
||||
${'androidAppBundle'} | ${'androidAppBundle'}
|
||||
${'androidStudioProject'} | ${'androidStudioProject'}
|
||||
`('returns $expected when $input is passed and androidAppBundle is not set', ({ input, expected }) => {
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue(input);
|
||||
expect(Input.androidExportType).toStrictEqual(expected);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// TODO: Remove in v3
|
||||
test.each`
|
||||
input | expected
|
||||
${'androidPackage'} | ${'androidPackage'}
|
||||
${'androidAppBundle'} | ${'androidAppBundle'}
|
||||
${'androidStudioProject'} | ${'androidStudioProject'}
|
||||
`('returns $expected when $input is passed and overrides androidAppBundle if it is set', ({ input, expected }) => {
|
||||
const spy = jest.spyOn(Input, 'getInput');
|
||||
spy.mockImplementationOnce(() => {
|
||||
return input;
|
||||
});
|
||||
|
||||
spy.mockImplementationOnce(() => {
|
||||
return true;
|
||||
});
|
||||
expect(Input.androidExportType).toStrictEqual(expected);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// TODO: Remove in v3
|
||||
test.each`
|
||||
input | expected
|
||||
${'true'} | ${'androidAppBundle'}
|
||||
${'false'} | ${'androidPackage'}
|
||||
`(
|
||||
'returns $expected when androidExportType is undefined and androidAppBundle is set to $input',
|
||||
({ input, expected }) => {
|
||||
const spy = jest.spyOn(Input, 'getInput');
|
||||
spy.mockImplementationOnce(() => {
|
||||
return;
|
||||
});
|
||||
|
||||
spy.mockImplementationOnce(() => {
|
||||
return input;
|
||||
});
|
||||
|
||||
expect(Input.androidExportType).toStrictEqual(expected);
|
||||
expect(spy).toHaveBeenCalledTimes(2);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('androidSymbolType', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.androidSymbolType).toStrictEqual('none');
|
||||
});
|
||||
|
||||
test.each`
|
||||
input | expected
|
||||
${'none'} | ${'none'}
|
||||
${'public'} | ${'public'}
|
||||
${'debugging'} | ${'debugging'}
|
||||
`('returns $expected when $input is passed', ({ input, expected }) => {
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue(input);
|
||||
expect(Input.androidExportType).toStrictEqual(expected);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('androidKeystoreName', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.androidKeystoreName).toStrictEqual('');
|
||||
|
||||
@@ -134,11 +134,28 @@ class Input {
|
||||
}
|
||||
|
||||
static get androidAppBundle() {
|
||||
core.warning('androidAppBundle is deprecated, please use androidExportType instead');
|
||||
const input = Input.getInput('androidAppBundle') || false;
|
||||
|
||||
return input === 'true';
|
||||
}
|
||||
|
||||
static get androidExportType() {
|
||||
// TODO: remove this in V3
|
||||
const exportType = Input.getInput('androidExportType');
|
||||
|
||||
if (exportType) {
|
||||
return exportType || 'androidPackage';
|
||||
}
|
||||
|
||||
return Input.androidAppBundle ? 'androidAppBundle' : 'androidPackage';
|
||||
|
||||
// End TODO
|
||||
|
||||
// Use this in V3 when androidAppBundle is removed
|
||||
// return Input.getInput('androidExportType') || 'androidPackage';
|
||||
}
|
||||
|
||||
static get androidKeystoreName() {
|
||||
return Input.getInput('androidKeystoreName') || '';
|
||||
}
|
||||
@@ -163,6 +180,10 @@ class Input {
|
||||
return Input.getInput('androidTargetSdkVersion') || '';
|
||||
}
|
||||
|
||||
static get androidSymbolType() {
|
||||
return Input.getInput('androidSymbolType') || 'none';
|
||||
}
|
||||
|
||||
static get sshAgent() {
|
||||
return Input.getInput('sshAgent') || '';
|
||||
}
|
||||
@@ -181,6 +202,18 @@ class Input {
|
||||
return input === 'true';
|
||||
}
|
||||
|
||||
static get cacheUnityInstallationOnMac() {
|
||||
const input = Input.getInput('cacheUnityInstallationOnMac') || false;
|
||||
|
||||
return input === 'true';
|
||||
}
|
||||
|
||||
static get unityHubVersionOnMac() {
|
||||
const input = Input.getInput('unityHubVersionOnMac') || '';
|
||||
|
||||
return input !== '' ? input : '';
|
||||
}
|
||||
|
||||
public static ToEnvVarFormat(input: string) {
|
||||
if (input.toUpperCase() === input) {
|
||||
return input;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { exec } from '@actions/exec';
|
||||
import { BuildParameters } from '.';
|
||||
import { execWithErrorCheck } from './exec-with-error-check';
|
||||
|
||||
class MacBuilder {
|
||||
public static async run(actionFolder, workspace, buildParameters: BuildParameters, silent = false) {
|
||||
await exec('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
||||
public static async run(actionFolder, silent = false) {
|
||||
await execWithErrorCheck('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
||||
silent,
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { BuildParameters } from '..';
|
||||
import { getUnityChangeset } from 'unity-changeset';
|
||||
import { exec } from '@actions/exec';
|
||||
import { exec, getExecOutput } from '@actions/exec';
|
||||
import { restoreCache, saveCache } from '@actions/cache';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
class SetupMac {
|
||||
static unityHubPath = `"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"`;
|
||||
static unityHubBasePath = `/Applications/"Unity Hub.app"`;
|
||||
static unityHubExecPath = `${SetupMac.unityHubBasePath}/Contents/MacOS/"Unity Hub"`;
|
||||
|
||||
public static async setup(buildParameters: BuildParameters, actionFolder: string) {
|
||||
const unityEditorPath = `/Applications/Unity/Hub/Editor/${buildParameters.editorVersion}/Unity.app/Contents/MacOS/Unity`;
|
||||
|
||||
if (!fs.existsSync(this.unityHubPath)) {
|
||||
await SetupMac.installUnityHub();
|
||||
if (!fs.existsSync(this.unityHubExecPath)) {
|
||||
await SetupMac.installUnityHub(buildParameters);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(unityEditorPath)) {
|
||||
@@ -20,45 +23,27 @@ class SetupMac {
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async installUnity(buildParameters: BuildParameters, silent = false) {
|
||||
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion);
|
||||
let command = `${this.unityHubPath} -- --headless install \
|
||||
--version ${buildParameters.editorVersion} \
|
||||
--changeset ${unityChangeset.changeset} `;
|
||||
|
||||
switch (buildParameters.targetPlatform) {
|
||||
case 'iOS':
|
||||
command += `--module ios `;
|
||||
break;
|
||||
case 'tvOS':
|
||||
command += '--module tvos ';
|
||||
break;
|
||||
case 'StandaloneOSX':
|
||||
command += `--module mac-il2cpp `;
|
||||
break;
|
||||
case 'Android':
|
||||
command += `--module android `;
|
||||
break;
|
||||
case 'WebGL':
|
||||
command += '--module webgl ';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported module for target platform: ${buildParameters.targetPlatform}.`);
|
||||
}
|
||||
|
||||
command += `--childModules`;
|
||||
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
|
||||
@@ -66,6 +51,83 @@ class SetupMac {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 '';
|
||||
}
|
||||
|
||||
private static getModuleParametersForTargetPlatform(targetPlatform: string): string {
|
||||
let moduleArgument = '';
|
||||
switch (targetPlatform) {
|
||||
case 'iOS':
|
||||
moduleArgument += `--module ios `;
|
||||
break;
|
||||
case 'tvOS':
|
||||
moduleArgument += '--module tvos ';
|
||||
break;
|
||||
case 'StandaloneOSX':
|
||||
moduleArgument += `--module mac-il2cpp `;
|
||||
break;
|
||||
case 'Android':
|
||||
moduleArgument += `--module android `;
|
||||
break;
|
||||
case 'WebGL':
|
||||
moduleArgument += '--module webgl ';
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 `;
|
||||
|
||||
// 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([unityEditorPath], key);
|
||||
}
|
||||
}
|
||||
|
||||
private static async setEnvironmentVariables(buildParameters: BuildParameters, actionFolder: string) {
|
||||
@@ -90,6 +152,8 @@ class SetupMac {
|
||||
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.ANDROID_EXPORT_TYPE = buildParameters.androidExportType;
|
||||
process.env.ANDROID_SYMBOL_TYPE = buildParameters.androidSymbolType;
|
||||
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
|
||||
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
||||
}
|
||||
|
||||
@@ -62,10 +62,15 @@ export default class Versioning {
|
||||
*/
|
||||
static async logDiff() {
|
||||
const diffCommand = `git --no-pager diff | head -n ${this.maxDiffLines.toString()}`;
|
||||
await System.run('sh', undefined, {
|
||||
input: Buffer.from(diffCommand),
|
||||
silent: true,
|
||||
});
|
||||
await System.run(
|
||||
'sh',
|
||||
undefined,
|
||||
{
|
||||
input: Buffer.from(diffCommand),
|
||||
silent: true,
|
||||
},
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,6 +312,6 @@ export default class Versioning {
|
||||
* Run git in the specified project path
|
||||
*/
|
||||
static async git(arguments_, options = {}) {
|
||||
return System.run('git', arguments_, { cwd: this.projectPath, ...options });
|
||||
return System.run('git', arguments_, { cwd: this.projectPath, ...options }, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user