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.`);
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -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"
#

View File

@@ -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
}

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 }
# 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