Skip to content

Commit 2afd9cd

Browse files
authored
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)
1 parent caa0a81 commit 2afd9cd

13 files changed

+143
-44
lines changed

action.yml

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ inputs:
124124
'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the
125125
default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
126126
applicable on Windows'
127+
containerRegistryRepository:
128+
required: false
129+
default: 'unityci/editor'
130+
description: 'Container registry and repository to pull image from. Only applicable if customImage is not set.'
131+
containerRegistryImageVersion:
132+
required: false
133+
default: '3'
134+
description: 'Container registry image version. Only applicable if customImage is not set.'
127135
allowDirtyBuild:
128136
required: false
129137
default: ''

dist/index.js

+41-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/platforms/mac/entrypoint.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
# Create directories for license activation
55
#
66

7-
sudo mkdir /Library/Application\ Support/Unity
8-
sudo chmod -R 777 /Library/Application\ Support/Unity
7+
UNITY_LICENSE_PATH="/Library/Application Support/Unity"
8+
9+
if [ ! -d "$UNITY_LICENSE_PATH" ]; then
10+
echo "Creating Unity License Directory"
11+
sudo mkdir -p "$UNITY_LICENSE_PATH"
12+
sudo chmod -R 777 "$UNITY_LICENSE_PATH"
13+
fi;
914

1015
ACTIVATE_LICENSE_PATH="$ACTION_FOLDER/BlankProject"
1116
mkdir -p "$ACTIVATE_LICENSE_PATH"
@@ -21,7 +26,6 @@ source $ACTION_FOLDER/platforms/mac/steps/return_license.sh
2126
# Remove license activation directory
2227
#
2328

24-
sudo rm -r /Library/Application\ Support/Unity
2529
rm -r "$ACTIVATE_LICENSE_PATH"
2630

2731
#

dist/platforms/windows/build.ps1

+13-10
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,29 @@ $unityArgs = @(
156156
# Remove null items as that will fail the Start-Process call
157157
$unityArgs = $unityArgs | Where-Object { $_ -ne $null }
158158

159-
$process = Start-Process -FilePath "$Env:UNITY_PATH\Editor\Unity.exe" `
159+
$unityProcess = Start-Process -FilePath "$Env:UNITY_PATH\Editor\Unity.exe" `
160160
-ArgumentList $unityArgs `
161161
-PassThru `
162162
-NoNewWindow
163163

164-
while (!$process.HasExited) {
165-
if ($process.HasExited) {
166-
Start-Sleep -Seconds 5
167-
Get-Process
164+
# Cache the handle so exit code works properly
165+
# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait
166+
$unityHandle = $unityProcess.Handle
168167

169-
Start-Sleep -Seconds 10
168+
while ($true) {
169+
if ($unityProcess.HasExited) {
170+
Start-Sleep -Seconds 3
170171
Get-Process
171172

173+
$BUILD_EXIT_CODE = $unityProcess.ExitCode
174+
172175
# Display results
173-
if ($process.ExitCode -eq 0)
176+
if ($BUILD_EXIT_CODE -eq 0)
174177
{
175178
Write-Output "Build Succeeded!!"
176179
} else
177180
{
178-
Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')"
181+
Write-Output "Build failed, with exit code $BUILD_EXIT_CODE"
179182
}
180183

181184
Write-Output ""
@@ -187,8 +190,8 @@ while (!$process.HasExited) {
187190
Get-ChildItem $Env:BUILD_PATH_FULL
188191
Write-Output ""
189192

190-
exit $process.ExitCode
193+
break
191194
}
192195

193-
Start-Sleep -Seconds 5
196+
Start-Sleep -Seconds 3
194197
}

dist/platforms/windows/entrypoint.ps1

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.
1212
Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force }
1313

1414
# Setup Git Credentials
15-
& "c:\steps\set_gitcredential.ps1"
15+
. "c:\steps\set_gitcredential.ps1"
1616

1717
# Activate Unity
18-
& "c:\steps\activate.ps1"
18+
. "c:\steps\activate.ps1"
1919

2020
# Build the project
21-
& "c:\steps\build.ps1"
21+
. "c:\steps\build.ps1"
2222

2323
# Free the seat for the activated license
24-
& "c:\steps\return_license.ps1"
24+
. "c:\steps\return_license.ps1"
2525

2626
Start-Sleep -Seconds 3
2727
Get-Process
28+
29+
exit $BUILD_EXIT_CODE

src/model/build-parameters.ts

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class BuildParameters {
4444
public dockerCpuLimit!: string;
4545
public dockerMemoryLimit!: string;
4646
public dockerIsolationMode!: string;
47+
public containerRegistryRepository!: string;
48+
public containerRegistryImageVersion!: string;
4749

4850
public customParameters!: string;
4951
public sshAgent!: string;
@@ -170,6 +172,8 @@ class BuildParameters {
170172
dockerCpuLimit: Input.dockerCpuLimit,
171173
dockerMemoryLimit: Input.dockerMemoryLimit,
172174
dockerIsolationMode: Input.dockerIsolationMode,
175+
containerRegistryRepository: Input.containerRegistryRepository,
176+
containerRegistryImageVersion: Input.containerRegistryImageVersion,
173177
providerStrategy: CloudRunnerOptions.providerStrategy,
174178
buildPlatform: CloudRunnerOptions.buildPlatform,
175179
kubeConfig: CloudRunnerOptions.kubeConfig,

src/model/docker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Docker {
1515
// eslint-disable-next-line unicorn/no-useless-undefined
1616
options: ExecOptions | undefined = undefined,
1717
entrypointBash: boolean = false,
18-
errorWhenMissingUnityBuildResults: boolean = true,
18+
errorWhenMissingUnityBuildResults: boolean = false,
1919
) {
2020
let runCommand = '';
2121
switch (process.platform) {

src/model/exec-with-error-check.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { getExecOutput, ExecOptions } from '@actions/exec';
1+
import { ExecOptions, getExecOutput } from '@actions/exec';
22

33
export async function execWithErrorCheck(
44
commandLine: string,
55
arguments_?: string[],
66
options?: ExecOptions,
7-
errorWhenMissingUnityBuildResults: boolean = true,
7+
errorWhenMissingUnityBuildResults: boolean = false,
88
): Promise<number> {
99
const result = await getExecOutput(commandLine, arguments_, options);
1010

src/model/image-tag.test.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ describe('ImageTag', () => {
55
editorVersion: '2099.9.f9f9',
66
targetPlatform: 'Test',
77
builderPlatform: '',
8+
containerRegistryRepository: 'unityci/editor',
9+
containerRegistryImageVersion: '3',
810
};
911

1012
const defaults = {
11-
repository: 'unityci',
12-
name: 'editor',
1313
image: 'unityci/editor',
1414
};
1515

@@ -21,8 +21,7 @@ describe('ImageTag', () => {
2121
it('accepts parameters and sets the right properties', () => {
2222
const image = new ImageTag(testImageParameters);
2323

24-
expect(image.repository).toStrictEqual('unityci');
25-
expect(image.name).toStrictEqual('editor');
24+
expect(image.repository).toStrictEqual('unityci/editor');
2625
expect(image.editorVersion).toStrictEqual(testImageParameters.editorVersion);
2726
expect(image.targetPlatform).toStrictEqual(testImageParameters.targetPlatform);
2827
expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform);
@@ -53,6 +52,8 @@ describe('ImageTag', () => {
5352
const image = new ImageTag({
5453
editorVersion: '2099.1.1111',
5554
targetPlatform: testImageParameters.targetPlatform,
55+
containerRegistryRepository: 'unityci/editor',
56+
containerRegistryImageVersion: '3',
5657
});
5758
switch (process.platform) {
5859
case 'win32':
@@ -68,6 +69,8 @@ describe('ImageTag', () => {
6869
editorVersion: '2099.1.1111',
6970
targetPlatform: testImageParameters.targetPlatform,
7071
customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
72+
containerRegistryRepository: 'unityci/editor',
73+
containerRegistryImageVersion: '3',
7174
});
7275

7376
expect(image.toString()).toStrictEqual(image.customImage);
@@ -77,6 +80,8 @@ describe('ImageTag', () => {
7780
const image = new ImageTag({
7881
editorVersion: '2019.2.11f1',
7982
targetPlatform: 'WebGL',
83+
containerRegistryRepository: 'unityci/editor',
84+
containerRegistryImageVersion: '3',
8085
});
8186

8287
switch (process.platform) {
@@ -93,6 +98,8 @@ describe('ImageTag', () => {
9398
const image = new ImageTag({
9499
editorVersion: '2019.2.11f1',
95100
targetPlatform: 'NoTarget',
101+
containerRegistryRepository: 'unityci/editor',
102+
containerRegistryImageVersion: '3',
96103
});
97104

98105
switch (process.platform) {

0 commit comments

Comments
 (0)