diff --git a/action.yml b/action.yml index ef48e8c2..47864bb2 100644 --- a/action.yml +++ b/action.yml @@ -106,6 +106,16 @@ 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 Windows docker container. Defaults to all available cores.' + dockerMemoryLimit: + required: false + default: '' + description: + 'Amount of memory to assign the Windows docker container. Defaults to 75% of total system memory rounded down to + the nearest gigabyte.' allowDirtyBuild: required: false default: '' diff --git a/dist/index.js b/dist/index.js index 9c38ab9a..a06da8b0 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index 2e82038a..6da9eaff 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index bd5f9103..3ecb4dbc 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -116,10 +116,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 { @@ -156,6 +158,8 @@ class BuildParameters { sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath, gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), chownFilesTo: Input.chownFilesTo, + dockerCpuLimit: Input.dockerCpuLimit, + dockerMemoryLimit: Input.dockerMemoryLimit, providerStrategy: CloudRunnerOptions.providerStrategy, buildPlatform: CloudRunnerOptions.buildPlatform, kubeConfig: CloudRunnerOptions.kubeConfig, diff --git a/src/model/docker.ts b/src/model/docker.ts index 24b93ab5..de0a9354 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -86,7 +86,15 @@ class Docker { } static getWindowsCommand(image: string, parameters: DockerParameters): string { - const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath } = parameters; + const { + workspace, + actionFolder, + unitySerial, + gitPrivateToken, + dockerWorkspacePath, + dockerCpuLimit, + dockerMemoryLimit, + } = parameters; return `docker run \ --workdir c:${dockerWorkspacePath} \ @@ -97,12 +105,15 @@ class Docker { ${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \ --volume "${workspace}":"c:${dockerWorkspacePath}" \ --volume "c:/regkeys":"c:/regkeys" \ + --volume "C:/Program Files/Microsoft Visual Studio":"C:/Program Files/Microsoft Visual Studio" \ --volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \ --volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \ --volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \ --volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \ --volume "${actionFolder}/platforms/windows":"c:/steps" \ --volume "${actionFolder}/BlankProject":"c:/BlankProject" \ + --cpus=${dockerCpuLimit} \ + --memory=${dockerMemoryLimit} \ ${image} \ powershell c:/steps/entrypoint.ps1`; } diff --git a/src/model/input.ts b/src/model/input.ts index f50b0633..fc9f447d 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -4,6 +4,7 @@ import { Cli } from './cli/cli'; import CloudRunnerQueryOverride from './cloud-runner/options/cloud-runner-query-override'; import Platform from './platform'; import GitHub from './github'; +import os from 'node:os'; import * as core from '@actions/core'; @@ -226,6 +227,16 @@ class Input { return Input.getInput('dockerWorkspacePath') || '/github/workspace'; } + static get dockerCpuLimit(): string { + return Input.getInput('dockerCpuLimit') || os.cpus().length.toString(); + } + + static get dockerMemoryLimit(): string { + const bytesInGigabyte = 1024 * 1024 * 1024; + + return Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInGigabyte) * 0.75)}G`; + } + public static ToEnvVarFormat(input: string) { if (input.toUpperCase() === input) { return input;