From 2afd9cd86f6f5f76f46578659fb082d1a6a7eca3 Mon Sep 17 00:00:00 2001 From: Andrew Kahr <22359829+AndrewKahr@users.noreply.github.com> Date: Wed, 15 Nov 2023 06:17:55 -0800 Subject: [PATCH] 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) --- action.yml | 8 +++++++ dist/index.js | Bin 22176169 -> 22177358 bytes dist/index.js.map | Bin 14646880 -> 14648317 bytes dist/platforms/mac/entrypoint.sh | 10 +++++--- dist/platforms/windows/build.ps1 | 23 ++++++++++-------- dist/platforms/windows/entrypoint.ps1 | 10 ++++---- src/model/build-parameters.ts | 4 ++++ src/model/docker.ts | 2 +- src/model/exec-with-error-check.ts | 4 ++-- src/model/image-tag.test.ts | 15 ++++++++---- src/model/image-tag.ts | 17 ++++++++----- src/model/input.ts | 8 +++++++ src/model/platform-setup/setup-mac.ts | 33 +++++++++++++++++++++++--- 13 files changed, 101 insertions(+), 33 deletions(-) diff --git a/action.yml b/action.yml index 2ada25e6..989c2569 100644 --- a/action.yml +++ b/action.yml @@ -124,6 +124,14 @@ inputs: 'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only applicable on Windows' + containerRegistryRepository: + required: false + default: 'unityci/editor' + description: 'Container registry and repository to pull image from. Only applicable if customImage is not set.' + containerRegistryImageVersion: + required: false + default: '3' + description: 'Container registry image version. Only applicable if customImage is not set.' allowDirtyBuild: required: false default: '' diff --git a/dist/index.js b/dist/index.js index 2bdb48110f7821d8198adbf28e6cc2fde896f6d4..dc3aac42a703b775526b6293e055ff2f7be75896 100644 GIT binary patch delta 2323 zcma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result = await getExecOutput(commandLine, arguments_, options); diff --git a/src/model/image-tag.test.ts b/src/model/image-tag.test.ts index 77934e5d..47adf65e 100644 --- a/src/model/image-tag.test.ts +++ b/src/model/image-tag.test.ts @@ -5,11 +5,11 @@ describe('ImageTag', () => { editorVersion: '2099.9.f9f9', targetPlatform: 'Test', builderPlatform: '', + containerRegistryRepository: 'unityci/editor', + containerRegistryImageVersion: '3', }; const defaults = { - repository: 'unityci', - name: 'editor', image: 'unityci/editor', }; @@ -21,8 +21,7 @@ describe('ImageTag', () => { it('accepts parameters and sets the right properties', () => { const image = new ImageTag(testImageParameters); - expect(image.repository).toStrictEqual('unityci'); - expect(image.name).toStrictEqual('editor'); + expect(image.repository).toStrictEqual('unityci/editor'); expect(image.editorVersion).toStrictEqual(testImageParameters.editorVersion); expect(image.targetPlatform).toStrictEqual(testImageParameters.targetPlatform); expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform); @@ -53,6 +52,8 @@ describe('ImageTag', () => { const image = new ImageTag({ editorVersion: '2099.1.1111', targetPlatform: testImageParameters.targetPlatform, + containerRegistryRepository: 'unityci/editor', + containerRegistryImageVersion: '3', }); switch (process.platform) { case 'win32': @@ -68,6 +69,8 @@ describe('ImageTag', () => { editorVersion: '2099.1.1111', targetPlatform: testImageParameters.targetPlatform, customImage: `${defaults.image}:2099.1.1111@347598437689743986`, + containerRegistryRepository: 'unityci/editor', + containerRegistryImageVersion: '3', }); expect(image.toString()).toStrictEqual(image.customImage); @@ -77,6 +80,8 @@ describe('ImageTag', () => { const image = new ImageTag({ editorVersion: '2019.2.11f1', targetPlatform: 'WebGL', + containerRegistryRepository: 'unityci/editor', + containerRegistryImageVersion: '3', }); switch (process.platform) { @@ -93,6 +98,8 @@ describe('ImageTag', () => { const image = new ImageTag({ editorVersion: '2019.2.11f1', targetPlatform: 'NoTarget', + containerRegistryRepository: 'unityci/editor', + containerRegistryImageVersion: '3', }); switch (process.platform) { diff --git a/src/model/image-tag.ts b/src/model/image-tag.ts index 35b4bbeb..cf484708 100644 --- a/src/model/image-tag.ts +++ b/src/model/image-tag.ts @@ -2,7 +2,6 @@ import Platform from './platform'; class ImageTag { public repository: string; - public name: string; public cloudRunnerBuilderPlatform!: string; public editorVersion: string; public targetPlatform: string; @@ -12,7 +11,14 @@ class ImageTag { public imagePlatformPrefix: string; constructor(imageProperties: { [key: string]: string }) { - 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}".`); @@ -23,8 +29,7 @@ class ImageTag { this.customImage = customImage; // Or - this.repository = 'unityci'; - this.name = 'editor'; + this.repository = containerRegistryRepository; this.editorVersion = editorVersion; this.targetPlatform = targetPlatform; this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform; @@ -33,7 +38,7 @@ class ImageTag { 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(): RegExp { @@ -156,7 +161,7 @@ class ImageTag { } get image(): string { - return `${this.repository}/${this.name}`.replace(/^\/+/, ''); + return `${this.repository}`.replace(/^\/+/, ''); } toString(): string { diff --git a/src/model/input.ts b/src/model/input.ts index 94a0f2b4..85f45733 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -256,6 +256,14 @@ class Input { return Input.getInput('dockerIsolationMode') || 'default'; } + static get containerRegistryRepository(): string { + return Input.getInput('containerRegistryRepository')!; + } + + static get containerRegistryImageVersion(): string { + return Input.getInput('containerRegistryImageVersion')!; + } + public static ToEnvVarFormat(input: string) { if (input.toUpperCase() === input) { return input; diff --git a/src/model/platform-setup/setup-mac.ts b/src/model/platform-setup/setup-mac.ts index d529d21f..70ce06f8 100644 --- a/src/model/platform-setup/setup-mac.ts +++ b/src/model/platform-setup/setup-mac.ts @@ -47,7 +47,10 @@ class SetupMac { // 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 }); + 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.`); } @@ -64,7 +67,9 @@ class SetupMac { private static async getLatestUnityHubVersion(): Promise { // 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 }); + const result = await getExecOutput(hubVersionCommand, undefined, { + silent: true, + }); if (result.exitCode === 0 && result.stdout !== '') { return result.stdout; } @@ -72,6 +77,23 @@ class SetupMac { return ''; } + private static getArchitectureParameters(): string[] { + 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; + } + private static getModuleParametersForTargetPlatform(targetPlatform: string): string[] { const moduleArgument = []; switch (targetPlatform) { @@ -111,6 +133,7 @@ class SetupMac { const unityChangeset = await getUnityChangeset(buildParameters.editorVersion); const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform); + const architectureArguments = SetupMac.getArchitectureParameters(); const execArguments: string[] = [ '--', @@ -119,12 +142,16 @@ 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 exec(this.unityHubExecPath, execArguments, { silent, ignoreReturnCode: true }); + const errorCode = await 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.`); }