Additional Fixes and Improvements (#596)

- Windows now exits with the proper exit codes. This mirrors Ubuntu behavior properly now and means we do not need the error parsing logic to handle error conditions which means we should be back to v2 behavior.
- Allow customizing image registry/image version
- Only create the licensing directory on Mac if it doesn't already exist. Don't delete the folder on build complete. This means builds nominally shouldn't need sudo permissions, very useful for self-hosted runners.
- Pick correct architecture when installing macos editor to support both x86 and arm-based systems (Credit @dcvz)
This commit is contained in:
Andrew Kahr
2023-11-15 06:17:55 -08:00
committed by GitHub
parent caa0a81b47
commit 2afd9cd86f
13 changed files with 143 additions and 44 deletions

51
dist/index.js generated vendored
View File

@@ -316,6 +316,8 @@ class BuildParameters {
dockerCpuLimit: input_1.default.dockerCpuLimit,
dockerMemoryLimit: input_1.default.dockerMemoryLimit,
dockerIsolationMode: input_1.default.dockerIsolationMode,
containerRegistryRepository: input_1.default.containerRegistryRepository,
containerRegistryImageVersion: input_1.default.containerRegistryImageVersion,
providerStrategy: cloud_runner_options_1.default.providerStrategy,
buildPlatform: cloud_runner_options_1.default.buildPlatform,
kubeConfig: cloud_runner_options_1.default.kubeConfig,
@@ -5899,7 +5901,7 @@ const node_path_1 = __importDefault(__nccwpck_require__(49411));
class Docker {
static async run(image, parameters, silent = false, overrideCommands = '', additionalVariables = [],
// eslint-disable-next-line unicorn/no-useless-undefined
options = undefined, entrypointBash = false, errorWhenMissingUnityBuildResults = true) {
options = undefined, entrypointBash = false, errorWhenMissingUnityBuildResults = false) {
let runCommand = '';
switch (process.platform) {
case 'linux':
@@ -6024,7 +6026,7 @@ exports["default"] = ValidationError;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.execWithErrorCheck = void 0;
const exec_1 = __nccwpck_require__(71514);
async function execWithErrorCheck(commandLine, arguments_, options, errorWhenMissingUnityBuildResults = true) {
async function execWithErrorCheck(commandLine, arguments_, options, errorWhenMissingUnityBuildResults = false) {
const result = await (0, exec_1.getExecOutput)(commandLine, arguments_, options);
if (!errorWhenMissingUnityBuildResults) {
return result.exitCode;
@@ -6386,7 +6388,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const platform_1 = __importDefault(__nccwpck_require__(9707));
class ImageTag {
constructor(imageProperties) {
const { editorVersion, targetPlatform, customImage, cloudRunnerBuilderPlatform } = imageProperties;
const { editorVersion, targetPlatform, customImage, cloudRunnerBuilderPlatform, containerRegistryRepository, containerRegistryImageVersion, } = imageProperties;
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
@@ -6394,15 +6396,14 @@ class ImageTag {
// Either
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.repository = containerRegistryRepository;
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform;
const isCloudRunnerLocal = cloudRunnerBuilderPlatform === 'local' || cloudRunnerBuilderPlatform === undefined;
this.builderPlatform = ImageTag.getTargetPlatformToTargetPlatformSuffixMap(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(isCloudRunnerLocal ? process.platform : cloudRunnerBuilderPlatform);
this.imageRollingVersion = 3; // Will automatically roll to the latest non-breaking version.
this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version.
}
static get versionPattern() {
return /^(20\d{2}\.\d\.\w{3,4}|3)$/;
@@ -6508,7 +6509,7 @@ class ImageTag {
return `${this.imagePlatformPrefix}-${versionAndPlatform}-${this.imageRollingVersion}`;
}
get image() {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
return `${this.repository}`.replace(/^\/+/, '');
}
toString() {
const { image, tag, customImage } = this;
@@ -6953,6 +6954,12 @@ class Input {
static get dockerIsolationMode() {
return Input.getInput('dockerIsolationMode') || 'default';
}
static get containerRegistryRepository() {
return Input.getInput('containerRegistryRepository');
}
static get containerRegistryImageVersion() {
return Input.getInput('containerRegistryImageVersion');
}
static ToEnvVarFormat(input) {
if (input.toUpperCase() === input) {
return input;
@@ -7190,7 +7197,10 @@ class SetupMac {
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 (0, exec_1.exec)(command, undefined, { silent, ignoreReturnCode: true });
const errorCode = await (0, exec_1.exec)(command, undefined, {
silent,
ignoreReturnCode: true,
});
if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
}
@@ -7205,12 +7215,28 @@ class SetupMac {
static async getLatestUnityHubVersion() {
// 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 (0, exec_1.getExecOutput)(hubVersionCommand, undefined, { silent: true });
const result = await (0, exec_1.getExecOutput)(hubVersionCommand, undefined, {
silent: true,
});
if (result.exitCode === 0 && result.stdout !== '') {
return result.stdout;
}
return '';
}
static getArchitectureParameters() {
const architectureArgument = [];
switch (process.arch) {
case 'x64':
architectureArgument.push('--architecture', 'x86_64');
break;
case 'arm64':
architectureArgument.push('--architecture', 'arm64');
break;
default:
throw new Error(`Unsupported architecture: ${process.arch}.`);
}
return architectureArgument;
}
static getModuleParametersForTargetPlatform(targetPlatform) {
const moduleArgument = [];
switch (targetPlatform) {
@@ -7246,6 +7272,7 @@ class SetupMac {
}
const unityChangeset = await (0, unity_changeset_1.getUnityChangeset)(buildParameters.editorVersion);
const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform);
const architectureArguments = SetupMac.getArchitectureParameters();
const execArguments = [
'--',
'--headless',
@@ -7253,11 +7280,15 @@ class SetupMac {
...['--version', buildParameters.editorVersion],
...['--changeset', unityChangeset.changeset],
...moduleArguments,
...architectureArguments,
'--childModules',
];
// Ignoring return code because the log seems to overflow the internal buffer which triggers
// a false error
const errorCode = await (0, exec_1.exec)(this.unityHubExecPath, execArguments, { silent, ignoreReturnCode: true });
const errorCode = await (0, exec_1.exec)(this.unityHubExecPath, execArguments, {
silent,
ignoreReturnCode: true,
});
if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
}