mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
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:
parent
caa0a81b47
commit
2afd9cd86f
@ -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: ''
|
||||
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
10
dist/platforms/mac/entrypoint.sh
vendored
10
dist/platforms/mac/entrypoint.sh
vendored
@ -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"
|
||||
|
||||
#
|
||||
|
23
dist/platforms/windows/build.ps1
vendored
23
dist/platforms/windows/build.ps1
vendored
@ -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
|
||||
}
|
||||
|
10
dist/platforms/windows/entrypoint.ps1
vendored
10
dist/platforms/windows/entrypoint.ps1
vendored
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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<number> {
|
||||
const result = await getExecOutput(commandLine, arguments_, options);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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<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 });
|
||||
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.`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user