Skip to content

Commit 4c4611c

Browse files
authored
Feature/windows upgrades (#588)
- Allow updating container memory and cpu limits for Windows. Previously, they defaulted to 1cpu and 1gb ram which was far too low and it seems docker wouldn't allocate all available resources. Now it will use all available cores and 80% of system memory. - Allow setting docker isolation mode for windows. Defaults to default to ensure behavior doesn't change from prior versions but now you can do stuff like force process mode on non-server versions which grants a performance uplift during runs - Added logic to allow building Android on Windows. Android doesn't support burst when built on Linux, only on Windows and macOS. Thus we need to allow building Android on WIndows due to the major performance benefits of Burst. - Support Windows 2022 and VS2022 by mounting the x64 Visual Studio path in addition to the x86 path to maintain compatibility with VS2019 and older - Attempted fixes for windows builds hanging by killing the regsvr32 process after registering VS dll and using a different method to launch Unity. Unsure if this is a definite fix so I am leaving in several debug calls to print out running processes so we have more data to work with on chasing down this bug. I suspect there's a process that's hanging around that isn't cleaning itself up or is getting into some kind of deadlock situation and needs to be killed. But the changes I've made have seen no hangs on building during docker test workflows when previously there would be at least 3-5 hanging builds.
1 parent 6419c87 commit 4c4611c

File tree

10 files changed

+224
-52
lines changed

10 files changed

+224
-52
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"configurations": [
3+
{
4+
"name": "PowerShell Launch Current File",
5+
"type": "PowerShell",
6+
"request": "launch",
7+
"script": "${file}",
8+
"cwd": "${cwd}"
9+
},
310
{
411
"type": "node",
512
"request": "launch",

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ inputs:
106106
default: ''
107107
description:
108108
'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
109+
dockerCpuLimit:
110+
required: false
111+
default: ''
112+
description: 'Number of CPU cores to assign the docker container. Defaults to all available cores on all platforms.'
113+
dockerMemoryLimit:
114+
required: false
115+
default: ''
116+
description:
117+
'Amount of memory to assign the docker container. Defaults to 95% of total system memory rounded down to the
118+
nearest megabyte on Linux and 80% on Windows. On unrecognized platforms, defaults to 75% of total system memory.
119+
To manually specify a value, use the format <number><unit>, where unit is either m or g. ie: 512m = 512 megabytes'
120+
dockerIsolationMode:
121+
required: false
122+
default: 'default'
123+
description:
124+
'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the
125+
default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
126+
applicable on Windows'
109127
allowDirtyBuild:
110128
required: false
111129
default: ''

dist/index.js

Lines changed: 47 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/platforms/windows/build.ps1

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ else
6666
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
6767
}
6868

69+
if ( "$Env:BUILD_TARGET" -eq "Android" -and -not ([string]::IsNullOrEmpty("$Env:ANDROID_KEYSTORE_BASE64")) )
70+
{
71+
Write-Output "Creating Android keystore."
72+
73+
# Write to consistent location as Windows Unity seems to have issues with pwd and can't find the keystore
74+
$keystorePath = "C:/android.keystore"
75+
[System.IO.File]::WriteAllBytes($keystorePath, [System.Convert]::FromBase64String($Env:ANDROID_KEYSTORE_BASE64))
76+
77+
# Ensure the project settings are pointed at the correct path
78+
$unitySettingsPath = "$Env:UNITY_PROJECT_PATH\ProjectSettings\ProjectSettings.asset"
79+
$fileContent = Get-Content -Path "$unitySettingsPath"
80+
$fileContent = $fileContent -replace "AndroidKeystoreName:\s+.*", "AndroidKeystoreName: $keystorePath"
81+
$fileContent | Set-Content -Path "$unitySettingsPath"
82+
83+
Write-Output "Created Android keystore."
84+
}
85+
else {
86+
Write-Output "Not creating Android keystore."
87+
}
88+
6989
#
7090
# Pre-build debug information
7191
#
@@ -112,48 +132,63 @@ Write-Output ""
112132
# If $Env:CUSTOM_PARAMETERS contains spaces and is passed directly on the command line to Unity, powershell will wrap it
113133
# in double quotes. To avoid this, parse $Env:CUSTOM_PARAMETERS into an array, while respecting any quotations within the string.
114134
$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS)
135+
$unityArgs = @(
136+
"-quit",
137+
"-batchmode",
138+
"-nographics",
139+
"-silent-crashes",
140+
"-projectPath", $Env:UNITY_PROJECT_PATH,
141+
"-executeMethod", $Env:BUILD_METHOD,
142+
"-buildTarget", $Env:BUILD_TARGET,
143+
"-customBuildTarget", $Env:BUILD_TARGET,
144+
"-customBuildPath", $Env:CUSTOM_BUILD_PATH,
145+
"-buildVersion", $Env:VERSION,
146+
"-androidVersionCode", $Env:ANDROID_VERSION_CODE,
147+
"-androidKeystorePass", $Env:ANDROID_KEYSTORE_PASS,
148+
"-androidKeyaliasName", $Env:ANDROID_KEYALIAS_NAME,
149+
"-androidKeyaliasPass", $Env:ANDROID_KEYALIAS_PASS,
150+
"-androidTargetSdkVersion", $Env:ANDROID_TARGET_SDK_VERSION,
151+
"-androidExportType", $Env:ANDROID_EXPORT_TYPE,
152+
"-androidSymbolType", $Env:ANDROID_SYMBOL_TYPE,
153+
"-logfile", "-"
154+
) + $customParametersArray
155+
156+
# Remove null items as that will fail the Start-Process call
157+
$unityArgs = $unityArgs | Where-Object { $_ -ne $null }
158+
159+
$process = Start-Process -FilePath "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" `
160+
-ArgumentList $unityArgs `
161+
-PassThru `
162+
-NoNewWindow
163+
164+
while (!$process.HasExited) {
165+
if ($process.HasExited) {
166+
Get-Process
167+
168+
Start-Sleep -Seconds 10
169+
170+
Get-Process
171+
172+
# Display results
173+
if ($process.ExitCode -eq 0)
174+
{
175+
Write-Output "Build Succeeded!!"
176+
} else
177+
{
178+
Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')"
179+
}
180+
181+
Write-Output ""
182+
Write-Output "###########################"
183+
Write-Output "# Build output #"
184+
Write-Output "###########################"
185+
Write-Output ""
186+
187+
Get-ChildItem $Env:BUILD_PATH_FULL
188+
Write-Output ""
189+
190+
exit $process.ExitCode
191+
}
115192

116-
& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -quit -batchmode -nographics `
117-
-projectPath $Env:UNITY_PROJECT_PATH `
118-
-executeMethod $Env:BUILD_METHOD `
119-
-buildTarget $Env:BUILD_TARGET `
120-
-customBuildTarget $Env:BUILD_TARGET `
121-
-customBuildPath $Env:CUSTOM_BUILD_PATH `
122-
-buildVersion $Env:VERSION `
123-
-androidVersionCode $Env:ANDROID_VERSION_CODE `
124-
-androidKeystoreName $Env:ANDROID_KEYSTORE_NAME `
125-
-androidKeystorePass $Env:ANDROID_KEYSTORE_PASS `
126-
-androidKeyaliasName $Env:ANDROID_KEYALIAS_NAME `
127-
-androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS `
128-
-androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION `
129-
-androidExportType $Env:ANDROID_EXPORT_TYPE `
130-
-androidSymbolType $Env:ANDROID_SYMBOL_TYPE `
131-
$customParametersArray `
132-
-logfile | Out-Host
133-
134-
# Catch exit code
135-
$Env:BUILD_EXIT_CODE=$LastExitCode
136-
137-
# Display results
138-
if ($Env:BUILD_EXIT_CODE -eq 0)
139-
{
140-
Write-Output "Build Succeeded!"
141-
} else
142-
{
143-
Write-Output "$('Build failed, with exit code ')$($Env:BUILD_EXIT_CODE)$('"')"
193+
Start-Sleep -Seconds 5
144194
}
145-
146-
# TODO: Determine if we need to set permissions on any files
147-
148-
#
149-
# Results
150-
#
151-
152-
Write-Output ""
153-
Write-Output "###########################"
154-
Write-Output "# Build output #"
155-
Write-Output "###########################"
156-
Write-Output ""
157-
158-
Get-ChildItem $Env:BUILD_PATH_FULL
159-
Write-Output ""

dist/platforms/windows/entrypoint.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
Get-Process
2+
13
# Import any necessary registry keys, ie: location of windows 10 sdk
24
# No guarantee that there will be any necessary registry keys, ie: tvOS
3-
Get-ChildItem -Path c:\regkeys -File | Foreach {reg import $_.fullname}
5+
Get-ChildItem -Path c:\regkeys -File | ForEach-Object {reg import $_.fullname}
46

57
# Register the Visual Studio installation so Unity can find it
68
regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.Setup.Configuration.Native.dll
79

10+
# Kill the regsvr process
11+
Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force }
12+
813
# Setup Git Credentials
914
& "c:\steps\set_gitcredential.ps1"
1015

@@ -16,3 +21,6 @@ regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.
1621

1722
# Free the seat for the activated license
1823
& "c:\steps\return_license.ps1"
24+
25+
Start-Sleep 3
26+
Get-Process

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ async function runMain() {
2525
if (process.platform === 'darwin') {
2626
MacBuilder.run(actionFolder);
2727
} else {
28-
await Docker.run(baseImage.toString(), { workspace, actionFolder, ...buildParameters });
28+
await Docker.run(baseImage.toString(), {
29+
workspace,
30+
actionFolder,
31+
...buildParameters,
32+
});
2933
}
3034
} else {
3135
await CloudRunner.run(buildParameters, baseImage.toString());
@@ -38,4 +42,5 @@ async function runMain() {
3842
core.setFailed((error as Error).message);
3943
}
4044
}
45+
4146
runMain();

src/model/build-parameters.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class BuildParameters {
4040
public androidSdkManagerParameters!: string;
4141
public androidExportType!: string;
4242
public androidSymbolType!: string;
43+
public dockerCpuLimit!: string;
44+
public dockerMemoryLimit!: string;
45+
public dockerIsolationMode!: string;
4346

4447
public customParameters!: string;
4548
public sshAgent!: string;
@@ -116,10 +119,12 @@ class BuildParameters {
116119
if (!Input.unitySerial && GitHub.githubInputEnabled) {
117120
// No serial was present, so it is a personal license that we need to convert
118121
if (!Input.unityLicense) {
119-
throw new Error(`Missing Unity License File and no Serial was found. If this
122+
throw new Error(
123+
`Missing Unity License File and no Serial was found. If this
120124
is a personal license, make sure to follow the activation
121125
steps and set the UNITY_LICENSE GitHub secret or enter a Unity
122-
serial number inside the UNITY_SERIAL GitHub secret.`);
126+
serial number inside the UNITY_SERIAL GitHub secret.`,
127+
);
123128
}
124129
unitySerial = this.getSerialFromLicenseFile(Input.unityLicense);
125130
} else {
@@ -156,6 +161,9 @@ class BuildParameters {
156161
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
157162
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
158163
chownFilesTo: Input.chownFilesTo,
164+
dockerCpuLimit: Input.dockerCpuLimit,
165+
dockerMemoryLimit: Input.dockerMemoryLimit,
166+
dockerIsolationMode: Input.dockerIsolationMode,
159167
providerStrategy: CloudRunnerOptions.providerStrategy,
160168
buildPlatform: CloudRunnerOptions.buildPlatform,
161169
kubeConfig: CloudRunnerOptions.kubeConfig,

0 commit comments

Comments
 (0)