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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 101 additions and 33 deletions

View File

@ -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 '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 default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
applicable on Windows' 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: allowDirtyBuild:
required: false required: false
default: '' default: ''

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -4,8 +4,13 @@
# Create directories for license activation # Create directories for license activation
# #
sudo mkdir /Library/Application\ Support/Unity UNITY_LICENSE_PATH="/Library/Application Support/Unity"
sudo chmod -R 777 /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" ACTIVATE_LICENSE_PATH="$ACTION_FOLDER/BlankProject"
mkdir -p "$ACTIVATE_LICENSE_PATH" mkdir -p "$ACTIVATE_LICENSE_PATH"
@ -21,7 +26,6 @@ source $ACTION_FOLDER/platforms/mac/steps/return_license.sh
# Remove license activation directory # Remove license activation directory
# #
sudo rm -r /Library/Application\ Support/Unity
rm -r "$ACTIVATE_LICENSE_PATH" rm -r "$ACTIVATE_LICENSE_PATH"
# #

View File

@ -156,26 +156,29 @@ $unityArgs = @(
# Remove null items as that will fail the Start-Process call # Remove null items as that will fail the Start-Process call
$unityArgs = $unityArgs | Where-Object { $_ -ne $null } $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 ` -ArgumentList $unityArgs `
-PassThru ` -PassThru `
-NoNewWindow -NoNewWindow
while (!$process.HasExited) { # Cache the handle so exit code works properly
if ($process.HasExited) { # https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait
Start-Sleep -Seconds 5 $unityHandle = $unityProcess.Handle
while ($true) {
if ($unityProcess.HasExited) {
Start-Sleep -Seconds 3
Get-Process Get-Process
Start-Sleep -Seconds 10 $BUILD_EXIT_CODE = $unityProcess.ExitCode
Get-Process
# Display results # Display results
if ($process.ExitCode -eq 0) if ($BUILD_EXIT_CODE -eq 0)
{ {
Write-Output "Build Succeeded!!" Write-Output "Build Succeeded!!"
} else } else
{ {
Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')" Write-Output "Build failed, with exit code $BUILD_EXIT_CODE"
} }
Write-Output "" Write-Output ""
@ -187,8 +190,8 @@ while (!$process.HasExited) {
Get-ChildItem $Env:BUILD_PATH_FULL Get-ChildItem $Env:BUILD_PATH_FULL
Write-Output "" Write-Output ""
exit $process.ExitCode break
} }
Start-Sleep -Seconds 5 Start-Sleep -Seconds 3
} }

View File

@ -12,16 +12,18 @@ regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.
Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force } Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force }
# Setup Git Credentials # Setup Git Credentials
& "c:\steps\set_gitcredential.ps1" . "c:\steps\set_gitcredential.ps1"
# Activate Unity # Activate Unity
& "c:\steps\activate.ps1" . "c:\steps\activate.ps1"
# Build the project # Build the project
& "c:\steps\build.ps1" . "c:\steps\build.ps1"
# Free the seat for the activated license # Free the seat for the activated license
& "c:\steps\return_license.ps1" . "c:\steps\return_license.ps1"
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
Get-Process Get-Process
exit $BUILD_EXIT_CODE

View File

@ -44,6 +44,8 @@ class BuildParameters {
public dockerCpuLimit!: string; public dockerCpuLimit!: string;
public dockerMemoryLimit!: string; public dockerMemoryLimit!: string;
public dockerIsolationMode!: string; public dockerIsolationMode!: string;
public containerRegistryRepository!: string;
public containerRegistryImageVersion!: string;
public customParameters!: string; public customParameters!: string;
public sshAgent!: string; public sshAgent!: string;
@ -170,6 +172,8 @@ class BuildParameters {
dockerCpuLimit: Input.dockerCpuLimit, dockerCpuLimit: Input.dockerCpuLimit,
dockerMemoryLimit: Input.dockerMemoryLimit, dockerMemoryLimit: Input.dockerMemoryLimit,
dockerIsolationMode: Input.dockerIsolationMode, dockerIsolationMode: Input.dockerIsolationMode,
containerRegistryRepository: Input.containerRegistryRepository,
containerRegistryImageVersion: Input.containerRegistryImageVersion,
providerStrategy: CloudRunnerOptions.providerStrategy, providerStrategy: CloudRunnerOptions.providerStrategy,
buildPlatform: CloudRunnerOptions.buildPlatform, buildPlatform: CloudRunnerOptions.buildPlatform,
kubeConfig: CloudRunnerOptions.kubeConfig, kubeConfig: CloudRunnerOptions.kubeConfig,

View File

@ -15,7 +15,7 @@ class Docker {
// eslint-disable-next-line unicorn/no-useless-undefined // eslint-disable-next-line unicorn/no-useless-undefined
options: ExecOptions | undefined = undefined, options: ExecOptions | undefined = undefined,
entrypointBash: boolean = false, entrypointBash: boolean = false,
errorWhenMissingUnityBuildResults: boolean = true, errorWhenMissingUnityBuildResults: boolean = false,
) { ) {
let runCommand = ''; let runCommand = '';
switch (process.platform) { switch (process.platform) {

View File

@ -1,10 +1,10 @@
import { getExecOutput, ExecOptions } from '@actions/exec'; import { ExecOptions, getExecOutput } from '@actions/exec';
export async function execWithErrorCheck( export async function execWithErrorCheck(
commandLine: string, commandLine: string,
arguments_?: string[], arguments_?: string[],
options?: ExecOptions, options?: ExecOptions,
errorWhenMissingUnityBuildResults: boolean = true, errorWhenMissingUnityBuildResults: boolean = false,
): Promise<number> { ): Promise<number> {
const result = await getExecOutput(commandLine, arguments_, options); const result = await getExecOutput(commandLine, arguments_, options);

View File

@ -5,11 +5,11 @@ describe('ImageTag', () => {
editorVersion: '2099.9.f9f9', editorVersion: '2099.9.f9f9',
targetPlatform: 'Test', targetPlatform: 'Test',
builderPlatform: '', builderPlatform: '',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
}; };
const defaults = { const defaults = {
repository: 'unityci',
name: 'editor',
image: 'unityci/editor', image: 'unityci/editor',
}; };
@ -21,8 +21,7 @@ describe('ImageTag', () => {
it('accepts parameters and sets the right properties', () => { it('accepts parameters and sets the right properties', () => {
const image = new ImageTag(testImageParameters); const image = new ImageTag(testImageParameters);
expect(image.repository).toStrictEqual('unityci'); expect(image.repository).toStrictEqual('unityci/editor');
expect(image.name).toStrictEqual('editor');
expect(image.editorVersion).toStrictEqual(testImageParameters.editorVersion); expect(image.editorVersion).toStrictEqual(testImageParameters.editorVersion);
expect(image.targetPlatform).toStrictEqual(testImageParameters.targetPlatform); expect(image.targetPlatform).toStrictEqual(testImageParameters.targetPlatform);
expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform); expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform);
@ -53,6 +52,8 @@ describe('ImageTag', () => {
const image = new ImageTag({ const image = new ImageTag({
editorVersion: '2099.1.1111', editorVersion: '2099.1.1111',
targetPlatform: testImageParameters.targetPlatform, targetPlatform: testImageParameters.targetPlatform,
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
}); });
switch (process.platform) { switch (process.platform) {
case 'win32': case 'win32':
@ -68,6 +69,8 @@ describe('ImageTag', () => {
editorVersion: '2099.1.1111', editorVersion: '2099.1.1111',
targetPlatform: testImageParameters.targetPlatform, targetPlatform: testImageParameters.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`, customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
}); });
expect(image.toString()).toStrictEqual(image.customImage); expect(image.toString()).toStrictEqual(image.customImage);
@ -77,6 +80,8 @@ describe('ImageTag', () => {
const image = new ImageTag({ const image = new ImageTag({
editorVersion: '2019.2.11f1', editorVersion: '2019.2.11f1',
targetPlatform: 'WebGL', targetPlatform: 'WebGL',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
}); });
switch (process.platform) { switch (process.platform) {
@ -93,6 +98,8 @@ describe('ImageTag', () => {
const image = new ImageTag({ const image = new ImageTag({
editorVersion: '2019.2.11f1', editorVersion: '2019.2.11f1',
targetPlatform: 'NoTarget', targetPlatform: 'NoTarget',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
}); });
switch (process.platform) { switch (process.platform) {

View File

@ -2,7 +2,6 @@ import Platform from './platform';
class ImageTag { class ImageTag {
public repository: string; public repository: string;
public name: string;
public cloudRunnerBuilderPlatform!: string; public cloudRunnerBuilderPlatform!: string;
public editorVersion: string; public editorVersion: string;
public targetPlatform: string; public targetPlatform: string;
@ -12,7 +11,14 @@ class ImageTag {
public imagePlatformPrefix: string; public imagePlatformPrefix: string;
constructor(imageProperties: { [key: string]: 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)) { if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`); throw new Error(`Invalid version "${editorVersion}".`);
@ -23,8 +29,7 @@ class ImageTag {
this.customImage = customImage; this.customImage = customImage;
// Or // Or
this.repository = 'unityci'; this.repository = containerRegistryRepository;
this.name = 'editor';
this.editorVersion = editorVersion; this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform; this.targetPlatform = targetPlatform;
this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform; this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform;
@ -33,7 +38,7 @@ class ImageTag {
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes( this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(
isCloudRunnerLocal ? process.platform : cloudRunnerBuilderPlatform, 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 { static get versionPattern(): RegExp {
@ -156,7 +161,7 @@ class ImageTag {
} }
get image(): string { get image(): string {
return `${this.repository}/${this.name}`.replace(/^\/+/, ''); return `${this.repository}`.replace(/^\/+/, '');
} }
toString(): string { toString(): string {

View File

@ -256,6 +256,14 @@ class Input {
return Input.getInput('dockerIsolationMode') || 'default'; 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) { public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) { if (input.toUpperCase() === input) {
return input; return input;

View File

@ -47,7 +47,10 @@ class SetupMac {
// Ignoring return code because the log seems to overflow the internal buffer which triggers // Ignoring return code because the log seems to overflow the internal buffer which triggers
// a false error // a false error
const errorCode = await exec(command, undefined, { silent, ignoreReturnCode: true }); const errorCode = await exec(command, undefined, {
silent,
ignoreReturnCode: true,
});
if (errorCode) { if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`); 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<string> { private static async getLatestUnityHubVersion(): Promise<string> {
// Need to check if the latest version available is the same as the one we have cached // 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 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 !== '') { if (result.exitCode === 0 && result.stdout !== '') {
return result.stdout; return result.stdout;
} }
@ -72,6 +77,23 @@ class SetupMac {
return ''; 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[] { private static getModuleParametersForTargetPlatform(targetPlatform: string): string[] {
const moduleArgument = []; const moduleArgument = [];
switch (targetPlatform) { switch (targetPlatform) {
@ -111,6 +133,7 @@ class SetupMac {
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion); const unityChangeset = await getUnityChangeset(buildParameters.editorVersion);
const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform); const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform);
const architectureArguments = SetupMac.getArchitectureParameters();
const execArguments: string[] = [ const execArguments: string[] = [
'--', '--',
@ -119,12 +142,16 @@ class SetupMac {
...['--version', buildParameters.editorVersion], ...['--version', buildParameters.editorVersion],
...['--changeset', unityChangeset.changeset], ...['--changeset', unityChangeset.changeset],
...moduleArguments, ...moduleArguments,
...architectureArguments,
'--childModules', '--childModules',
]; ];
// Ignoring return code because the log seems to overflow the internal buffer which triggers // Ignoring return code because the log seems to overflow the internal buffer which triggers
// a false error // 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) { if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`); throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
} }