Skip to content

Commit

Permalink
Additional Fixes and Improvements (#596)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
AndrewKahr authored Nov 15, 2023
1 parent caa0a81 commit 2afd9cd
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 44 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
51 changes: 41 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/platforms/mac/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

#
Expand Down
23 changes: 13 additions & 10 deletions dist/platforms/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Get-Process
# 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

Start-Sleep -Seconds 10
while ($true) {
if ($unityProcess.HasExited) {
Start-Sleep -Seconds 3
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 ""
Expand All @@ -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 changes: 6 additions & 4 deletions dist/platforms/windows/entrypoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/model/build-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/model/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/exec-with-error-check.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
15 changes: 11 additions & 4 deletions src/model/image-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand All @@ -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);
Expand Down Expand Up @@ -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':
Expand All @@ -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);
Expand All @@ -77,6 +80,8 @@ describe('ImageTag', () => {
const image = new ImageTag({
editorVersion: '2019.2.11f1',
targetPlatform: 'WebGL',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});

switch (process.platform) {
Expand All @@ -93,6 +98,8 @@ describe('ImageTag', () => {
const image = new ImageTag({
editorVersion: '2019.2.11f1',
targetPlatform: 'NoTarget',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});

switch (process.platform) {
Expand Down
Loading

0 comments on commit 2afd9cd

Please sign in to comment.