Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/windows upgrades #588

Merged
merged 26 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
70ae34a
Stop regsvr32 to prevent hanging on exit
AndrewKahr Oct 15, 2023
1f5e83e
Fix pathing issues for android keystore
AndrewKahr Oct 16, 2023
2b57efd
Setup memory/cpu limits for windows containers
AndrewKahr Oct 17, 2023
23efedb
Fix pathing issue
AndrewKahr Oct 17, 2023
44d4fb4
Debug prints
AndrewKahr Oct 18, 2023
d74bb9d
More debug prints
AndrewKahr Oct 19, 2023
32e3b41
Use different method to run unity to ensure it exits without hanging
AndrewKahr Oct 22, 2023
99e0cc4
Debug prints
AndrewKahr Oct 22, 2023
092e54d
Debug remove parameter array
AndrewKahr Oct 22, 2023
988d7e1
More debug
AndrewKahr Oct 22, 2023
24e05f8
More debug
AndrewKahr Oct 22, 2023
79c2e08
More debug
AndrewKahr Oct 22, 2023
908b8af
Fix null arg
AndrewKahr Oct 22, 2023
c7da222
Build array before call
AndrewKahr Oct 22, 2023
ed6252c
Fix logic issue
AndrewKahr Oct 22, 2023
41cf9f3
Revert unity call
AndrewKahr Oct 22, 2023
53f6978
Attempt to fix windows exit hang
AndrewKahr Oct 27, 2023
6f16f5f
Additional debug changes for fixing windows hanging
AndrewKahr Oct 27, 2023
10c4e7f
Output to console
AndrewKahr Oct 27, 2023
c59b213
Debugging
AndrewKahr Oct 27, 2023
9e22e88
Code cleanup
AndrewKahr Oct 27, 2023
d47dc75
Provide a default for linux to allow providing a custom limit on linu…
AndrewKahr Oct 27, 2023
974b785
Switch to process isolation mode by default and give an option to use…
AndrewKahr Oct 28, 2023
3375d93
Fix isolation mode to use default by default
AndrewKahr Oct 28, 2023
7e27d29
Merge branch 'main' into feature/windows-upgrades
AndrewKahr Oct 28, 2023
12c712d
Update isolation mode description
AndrewKahr Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"configurations": [
{
"name": "PowerShell Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${cwd}"
},
{
"type": "node",
"request": "launch",
Expand Down
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ inputs:
default: ''
description:
'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
dockerCpuLimit:
required: false
default: ''
description: 'Number of CPU cores to assign the docker container. Defaults to all available cores on all platforms.'
dockerMemoryLimit:
required: false
default: ''
description:
'Amount of memory to assign the docker container. Defaults to 95% of total system memory rounded down to the
nearest megabyte on Linux and 80% on Windows. On unrecognized platforms, defaults to 75% of total system memory.
To manually specify a value, use the format <number><unit>, where unit is either m or g. ie: 512m = 512 megabytes'
dockerIsolationMode:
required: false
default: 'default'
AndrewKahr marked this conversation as resolved.
Show resolved Hide resolved
description:
'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'
allowDirtyBuild:
required: false
default: ''
Expand Down
50 changes: 47 additions & 3 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.

121 changes: 78 additions & 43 deletions dist/platforms/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ else
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
}

if ( "$Env:BUILD_TARGET" -eq "Android" -and -not ([string]::IsNullOrEmpty("$Env:ANDROID_KEYSTORE_BASE64")) )
{
Write-Output "Creating Android keystore."

# Write to consistent location as Windows Unity seems to have issues with pwd and can't find the keystore
$keystorePath = "C:/android.keystore"
[System.IO.File]::WriteAllBytes($keystorePath, [System.Convert]::FromBase64String($Env:ANDROID_KEYSTORE_BASE64))

# Ensure the project settings are pointed at the correct path
$unitySettingsPath = "$Env:UNITY_PROJECT_PATH\ProjectSettings\ProjectSettings.asset"
$fileContent = Get-Content -Path "$unitySettingsPath"
$fileContent = $fileContent -replace "AndroidKeystoreName:\s+.*", "AndroidKeystoreName: $keystorePath"
$fileContent | Set-Content -Path "$unitySettingsPath"

Write-Output "Created Android keystore."
}
else {
Write-Output "Not creating Android keystore."
}

#
# Pre-build debug information
#
Expand Down Expand Up @@ -112,48 +132,63 @@ Write-Output ""
# If $Env:CUSTOM_PARAMETERS contains spaces and is passed directly on the command line to Unity, powershell will wrap it
# in double quotes. To avoid this, parse $Env:CUSTOM_PARAMETERS into an array, while respecting any quotations within the string.
$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS)
$unityArgs = @(
"-quit",
"-batchmode",
"-nographics",
"-silent-crashes",
"-projectPath", $Env:UNITY_PROJECT_PATH,
"-executeMethod", $Env:BUILD_METHOD,
"-buildTarget", $Env:BUILD_TARGET,
"-customBuildTarget", $Env:BUILD_TARGET,
"-customBuildPath", $Env:CUSTOM_BUILD_PATH,
"-buildVersion", $Env:VERSION,
"-androidVersionCode", $Env:ANDROID_VERSION_CODE,
"-androidKeystorePass", $Env:ANDROID_KEYSTORE_PASS,
"-androidKeyaliasName", $Env:ANDROID_KEYALIAS_NAME,
"-androidKeyaliasPass", $Env:ANDROID_KEYALIAS_PASS,
"-androidTargetSdkVersion", $Env:ANDROID_TARGET_SDK_VERSION,
"-androidExportType", $Env:ANDROID_EXPORT_TYPE,
"-androidSymbolType", $Env:ANDROID_SYMBOL_TYPE,
"-logfile", "-"
) + $customParametersArray

# Remove null items as that will fail the Start-Process call
$unityArgs = $unityArgs | Where-Object { $_ -ne $null }

$process = Start-Process -FilePath "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" `
-ArgumentList $unityArgs `
-PassThru `
-NoNewWindow

while (!$process.HasExited) {
if ($process.HasExited) {
Get-Process

Start-Sleep -Seconds 10

Get-Process

# Display results
if ($process.ExitCode -eq 0)
{
Write-Output "Build Succeeded!!"
} else
{
Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')"
}

Write-Output ""
Write-Output "###########################"
Write-Output "# Build output #"
Write-Output "###########################"
Write-Output ""

Get-ChildItem $Env:BUILD_PATH_FULL
Write-Output ""

exit $process.ExitCode
}

& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -quit -batchmode -nographics `
-projectPath $Env:UNITY_PROJECT_PATH `
-executeMethod $Env:BUILD_METHOD `
-buildTarget $Env:BUILD_TARGET `
-customBuildTarget $Env:BUILD_TARGET `
-customBuildPath $Env:CUSTOM_BUILD_PATH `
-buildVersion $Env:VERSION `
-androidVersionCode $Env:ANDROID_VERSION_CODE `
-androidKeystoreName $Env:ANDROID_KEYSTORE_NAME `
-androidKeystorePass $Env:ANDROID_KEYSTORE_PASS `
-androidKeyaliasName $Env:ANDROID_KEYALIAS_NAME `
-androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS `
-androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION `
-androidExportType $Env:ANDROID_EXPORT_TYPE `
-androidSymbolType $Env:ANDROID_SYMBOL_TYPE `
$customParametersArray `
-logfile | Out-Host

# Catch exit code
$Env:BUILD_EXIT_CODE=$LastExitCode

# Display results
if ($Env:BUILD_EXIT_CODE -eq 0)
{
Write-Output "Build Succeeded!"
} else
{
Write-Output "$('Build failed, with exit code ')$($Env:BUILD_EXIT_CODE)$('"')"
Start-Sleep -Seconds 5
}

# TODO: Determine if we need to set permissions on any files

#
# Results
#

Write-Output ""
Write-Output "###########################"
Write-Output "# Build output #"
Write-Output "###########################"
Write-Output ""

Get-ChildItem $Env:BUILD_PATH_FULL
Write-Output ""
10 changes: 9 additions & 1 deletion dist/platforms/windows/entrypoint.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Get-Process

# Import any necessary registry keys, ie: location of windows 10 sdk
# No guarantee that there will be any necessary registry keys, ie: tvOS
Get-ChildItem -Path c:\regkeys -File | Foreach {reg import $_.fullname}
Get-ChildItem -Path c:\regkeys -File | ForEach-Object {reg import $_.fullname}

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

# Kill the regsvr process
Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force }

# Setup Git Credentials
& "c:\steps\set_gitcredential.ps1"

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

# Free the seat for the activated license
& "c:\steps\return_license.ps1"

Start-Sleep 3
Get-Process
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ async function runMain() {
if (process.platform === 'darwin') {
MacBuilder.run(actionFolder);
} else {
await Docker.run(baseImage.toString(), { workspace, actionFolder, ...buildParameters });
await Docker.run(baseImage.toString(), {
workspace,
actionFolder,
...buildParameters,
});
}
} else {
await CloudRunner.run(buildParameters, baseImage.toString());
Expand All @@ -38,4 +42,5 @@ async function runMain() {
core.setFailed((error as Error).message);
}
}

runMain();
12 changes: 10 additions & 2 deletions src/model/build-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class BuildParameters {
public androidSdkManagerParameters!: string;
public androidExportType!: string;
public androidSymbolType!: string;
public dockerCpuLimit!: string;
public dockerMemoryLimit!: string;
public dockerIsolationMode!: string;

public customParameters!: string;
public sshAgent!: string;
Expand Down Expand Up @@ -116,10 +119,12 @@ class BuildParameters {
if (!Input.unitySerial && GitHub.githubInputEnabled) {
// No serial was present, so it is a personal license that we need to convert
if (!Input.unityLicense) {
throw new Error(`Missing Unity License File and no Serial was found. If this
throw new Error(
`Missing Unity License File and no Serial was found. If this
is a personal license, make sure to follow the activation
steps and set the UNITY_LICENSE GitHub secret or enter a Unity
serial number inside the UNITY_SERIAL GitHub secret.`);
serial number inside the UNITY_SERIAL GitHub secret.`,
);
}
unitySerial = this.getSerialFromLicenseFile(Input.unityLicense);
} else {
Expand Down Expand Up @@ -156,6 +161,9 @@ class BuildParameters {
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
chownFilesTo: Input.chownFilesTo,
dockerCpuLimit: Input.dockerCpuLimit,
dockerMemoryLimit: Input.dockerMemoryLimit,
dockerIsolationMode: Input.dockerIsolationMode,
providerStrategy: CloudRunnerOptions.providerStrategy,
buildPlatform: CloudRunnerOptions.buildPlatform,
kubeConfig: CloudRunnerOptions.kubeConfig,
Expand Down
Loading
Loading