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 2bdb4811..dc3aac42 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index a47bee96..6f16cb34 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/dist/platforms/mac/entrypoint.sh b/dist/platforms/mac/entrypoint.sh index 37cf7a4b..80ec6d09 100755 --- a/dist/platforms/mac/entrypoint.sh +++ b/dist/platforms/mac/entrypoint.sh @@ -4,8 +4,13 @@ # Create directories for license activation # -sudo mkdir /Library/Application\ Support/Unity -sudo chmod -R 777 /Library/Application\ Support/Unity +UNITY_LICENSE_PATH="/Library/Application Support/Unity" + +if [ ! -d "$UNITY_LICENSE_PATH" ]; then + echo "Creating Unity License Directory" + sudo mkdir -p "$UNITY_LICENSE_PATH" + sudo chmod -R 777 "$UNITY_LICENSE_PATH" +fi; ACTIVATE_LICENSE_PATH="$ACTION_FOLDER/BlankProject" mkdir -p "$ACTIVATE_LICENSE_PATH" @@ -21,7 +26,6 @@ source $ACTION_FOLDER/platforms/mac/steps/return_license.sh # Remove license activation directory # -sudo rm -r /Library/Application\ Support/Unity rm -r "$ACTIVATE_LICENSE_PATH" # diff --git a/dist/platforms/windows/build.ps1 b/dist/platforms/windows/build.ps1 index e8727618..751cf9d2 100644 --- a/dist/platforms/windows/build.ps1 +++ b/dist/platforms/windows/build.ps1 @@ -156,26 +156,29 @@ $unityArgs = @( # Remove null items as that will fail the Start-Process call $unityArgs = $unityArgs | Where-Object { $_ -ne $null } -$process = Start-Process -FilePath "$Env:UNITY_PATH\Editor\Unity.exe" ` +$unityProcess = Start-Process -FilePath "$Env:UNITY_PATH\Editor\Unity.exe" ` -ArgumentList $unityArgs ` -PassThru ` -NoNewWindow -while (!$process.HasExited) { - if ($process.HasExited) { - Start-Sleep -Seconds 5 +# Cache the handle so exit code works properly +# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait +$unityHandle = $unityProcess.Handle + +while ($true) { + if ($unityProcess.HasExited) { + Start-Sleep -Seconds 3 Get-Process - Start-Sleep -Seconds 10 - Get-Process + $BUILD_EXIT_CODE = $unityProcess.ExitCode # Display results - if ($process.ExitCode -eq 0) + if ($BUILD_EXIT_CODE -eq 0) { Write-Output "Build Succeeded!!" } else { - Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')" + Write-Output "Build failed, with exit code $BUILD_EXIT_CODE" } Write-Output "" @@ -187,8 +190,8 @@ while (!$process.HasExited) { Get-ChildItem $Env:BUILD_PATH_FULL Write-Output "" - exit $process.ExitCode + break } - Start-Sleep -Seconds 5 + Start-Sleep -Seconds 3 } diff --git a/dist/platforms/windows/entrypoint.ps1 b/dist/platforms/windows/entrypoint.ps1 index f156863d..07cbb070 100644 --- a/dist/platforms/windows/entrypoint.ps1 +++ b/dist/platforms/windows/entrypoint.ps1 @@ -12,16 +12,18 @@ regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio. Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force } # Setup Git Credentials -& "c:\steps\set_gitcredential.ps1" +. "c:\steps\set_gitcredential.ps1" # Activate Unity -& "c:\steps\activate.ps1" +. "c:\steps\activate.ps1" # Build the project -& "c:\steps\build.ps1" +. "c:\steps\build.ps1" # Free the seat for the activated license -& "c:\steps\return_license.ps1" +. "c:\steps\return_license.ps1" Start-Sleep -Seconds 3 Get-Process + +exit $BUILD_EXIT_CODE diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index 4cd8a523..a91e165e 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -44,6 +44,8 @@ class BuildParameters { public dockerCpuLimit!: string; public dockerMemoryLimit!: string; public dockerIsolationMode!: string; + public containerRegistryRepository!: string; + public containerRegistryImageVersion!: string; public customParameters!: string; public sshAgent!: string; @@ -170,6 +172,8 @@ class BuildParameters { dockerCpuLimit: Input.dockerCpuLimit, dockerMemoryLimit: Input.dockerMemoryLimit, dockerIsolationMode: Input.dockerIsolationMode, + containerRegistryRepository: Input.containerRegistryRepository, + containerRegistryImageVersion: Input.containerRegistryImageVersion, providerStrategy: CloudRunnerOptions.providerStrategy, buildPlatform: CloudRunnerOptions.buildPlatform, kubeConfig: CloudRunnerOptions.kubeConfig, diff --git a/src/model/docker.ts b/src/model/docker.ts index 77645666..50cbf69f 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -15,7 +15,7 @@ class Docker { // eslint-disable-next-line unicorn/no-useless-undefined options: ExecOptions | undefined = undefined, entrypointBash: boolean = false, - errorWhenMissingUnityBuildResults: boolean = true, + errorWhenMissingUnityBuildResults: boolean = false, ) { let runCommand = ''; switch (process.platform) { diff --git a/src/model/exec-with-error-check.ts b/src/model/exec-with-error-check.ts index 3240a07d..3fe3030b 100644 --- a/src/model/exec-with-error-check.ts +++ b/src/model/exec-with-error-check.ts @@ -1,10 +1,10 @@ -import { getExecOutput, ExecOptions } from '@actions/exec'; +import { ExecOptions, getExecOutput } from '@actions/exec'; export async function execWithErrorCheck( commandLine: string, arguments_?: string[], options?: ExecOptions, - errorWhenMissingUnityBuildResults: boolean = true, + errorWhenMissingUnityBuildResults: boolean = false, ): Promise { const 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.`); }