diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d7aa5408..9eb8d367 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,13 +2,21 @@ - ... +#### Related Issues + +- ... + +#### Related PRs + +- ... + #### Checklist - [x] Read the contribution [guide](https://github.com/game-ci/unity-builder/blob/main/CONTRIBUTING.md) and accept the [code](https://github.com/game-ci/unity-builder/blob/main/CODE_OF_CONDUCT.md) of conduct -- [ ] Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make - a PR in the [documentation repo](https://github.com/game-ci/documentation)) +- [ ] Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make a PR + in the [documentation repo](https://github.com/game-ci/documentation)) - [ ] Readme (updated or not needed) - [ ] Tests (added, updated or not needed) diff --git a/.github/workflows/activation.yml b/.github/workflows/activation.yml index 7299db23..2ceef255 100644 --- a/.github/workflows/activation.yml +++ b/.github/workflows/activation.yml @@ -13,7 +13,7 @@ jobs: id: requestActivationFile uses: game-ci/unity-request-activation-file@v2.0-alpha-1 - name: Upload activation file - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ${{ steps.requestActivationFile.outputs.filePath }} path: ${{ steps.requestActivationFile.outputs.filePath }} diff --git a/.github/workflows/build-tests-mac.yml b/.github/workflows/build-tests-mac.yml index b3e1cf4d..860fb1ea 100644 --- a/.github/workflows/build-tests-mac.yml +++ b/.github/workflows/build-tests-mac.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true jobs: - buildForAllPlatformsWindows: + buildForAllPlatformsMacOS: name: ${{ matrix.targetPlatform }} on ${{ matrix.unityVersion }} runs-on: macos-latest strategy: @@ -20,11 +20,9 @@ jobs: projectPath: - test-project unityVersion: - - 2021.3.29f1 - - 2022.1.24f1 - - 2022.2.21f1 - - 2022.3.7f1 - - 2023.1.8f1 + - 2021.3.31f1 + - 2022.3.11f1 + - 2023.1.17f1 targetPlatform: - StandaloneOSX # Build a MacOS executable @@ -32,7 +30,7 @@ jobs: ########################### # Checkout # ########################### - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: lfs: true diff --git a/.github/workflows/build-tests-ubuntu.yml b/.github/workflows/build-tests-ubuntu.yml index 265126cf..60ddfdcf 100644 --- a/.github/workflows/build-tests-ubuntu.yml +++ b/.github/workflows/build-tests-ubuntu.yml @@ -52,11 +52,9 @@ jobs: projectPath: - test-project unityVersion: - - 2021.3.29f1 - - 2022.1.24f1 - - 2022.2.21f1 - - 2022.3.7f1 - - 2023.1.8f1 + - 2021.3.31f1 + - 2022.3.11f1 + - 2023.1.17f1 targetPlatform: - StandaloneOSX # Build a macOS standalone (Intel 64-bit) with mono backend. - StandaloneWindows64 # Build a Windows 64-bit standalone with mono backend. @@ -64,17 +62,11 @@ jobs: - iOS # Build an iOS player. - Android # Build an Android .apk. - WebGL # WebGL. - # - StandaloneWindows # Build a Windows standalone. - # - WSAPlayer # Build an Windows Store Apps player. - # - PS4 # Build a PS4 Standalone. - # - XboxOne # Build a Xbox One Standalone. - # - tvOS # Build to Apple's tvOS platform. - # - Switch # Build a Nintendo Switch player steps: ########################### # Checkout # ########################### - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: lfs: true diff --git a/.github/workflows/build-tests-windows.yml b/.github/workflows/build-tests-windows.yml index 02dae84b..8c0e6e3c 100644 --- a/.github/workflows/build-tests-windows.yml +++ b/.github/workflows/build-tests-windows.yml @@ -13,19 +13,18 @@ concurrency: jobs: buildForAllPlatformsWindows: name: ${{ matrix.targetPlatform }} on ${{ matrix.unityVersion }} - runs-on: windows-2019 + runs-on: windows-2022 strategy: fail-fast: false matrix: projectPath: - test-project unityVersion: - - 2021.3.29f1 - - 2022.1.24f1 - - 2022.2.21f1 - - 2022.3.7f1 - - 2023.1.8f1 + - 2021.3.31f1 + - 2022.3.11f1 + - 2023.1.17f1 targetPlatform: + - Android # Build an Android apk. - StandaloneWindows64 # Build a Windows 64-bit standalone. - StandaloneWindows # Build a Windows 32-bit standalone. - WSAPlayer # Build a UWP App @@ -35,7 +34,7 @@ jobs: ########################### # Checkout # ########################### - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: lfs: true diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml index 48f82d53..c62c2aee 100644 --- a/.github/workflows/cleanup.yml +++ b/.github/workflows/cleanup.yml @@ -15,11 +15,11 @@ jobs: cleanupCloudRunner: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 if: github.event.event_type != 'pull_request_target' with: lfs: true - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: '18' - run: yarn diff --git a/.github/workflows/cloud-runner-ci-pipeline.yml b/.github/workflows/cloud-runner-ci-pipeline.yml index 4704defa..efe186b7 100644 --- a/.github/workflows/cloud-runner-ci-pipeline.yml +++ b/.github/workflows/cloud-runner-ci-pipeline.yml @@ -56,7 +56,7 @@ jobs: #- k8s steps: - name: Checkout (default) - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: lfs: false - name: Configure AWS Credentials @@ -116,7 +116,7 @@ jobs: #- 'cloud-runner-locking-get-locked' steps: - name: Checkout (default) - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: lfs: false - name: Configure AWS Credentials @@ -167,7 +167,7 @@ jobs: - Android # Build an Android .apk. steps: - name: Checkout (default) - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: lfs: false - run: yarn diff --git a/.github/workflows/integrity-check.yml b/.github/workflows/integrity-check.yml index 64e01b29..3c43650b 100644 --- a/.github/workflows/integrity-check.yml +++ b/.github/workflows/integrity-check.yml @@ -16,8 +16,8 @@ jobs: name: Tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: '18' - run: yarn diff --git a/.vscode/launch.json b/.vscode/launch.json index 9c7be0a5..ade9bd7b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,5 +1,12 @@ { "configurations": [ + { + "name": "PowerShell Launch Current File", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "cwd": "${cwd}" + }, { "type": "node", "request": "launch", diff --git a/action.yml b/action.yml index ef48e8c2..2ada25e6 100644 --- a/action.yml +++ b/action.yml @@ -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 , where unit is either m or g. ie: 512m = 512 megabytes' + dockerIsolationMode: + required: false + default: 'default' + 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: '' diff --git a/dist/index.js b/dist/index.js index 9c38ab9a..6003d75d 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 ca610bdb..560e37b1 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/dist/platforms/ubuntu/steps/build.sh b/dist/platforms/ubuntu/steps/build.sh index a066e4ed..7a202bab 100755 --- a/dist/platforms/ubuntu/steps/build.sh +++ b/dist/platforms/ubuntu/steps/build.sh @@ -69,7 +69,15 @@ fi if [[ "$BUILD_TARGET" == "Android" && -n "$ANDROID_SDK_MANAGER_PARAMETERS" ]]; then echo "Updating Android SDK with parameters: $ANDROID_SDK_MANAGER_PARAMETERS" export JAVA_HOME="$(awk -F'=' '/JAVA_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" - "$(awk -F'=' '/ANDROID_HOME=/{print $2}' /usr/bin/unity-editor.d/*)/tools/bin/sdkmanager" "$ANDROID_SDK_MANAGER_PARAMETERS" + ANDROID_HOME_DIRECTORY="$(awk -F'=' '/ANDROID_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" + SDKMANAGER=$(find $ANDROID_HOME_DIRECTORY/cmdline-tools -name sdkmanager) + if [ -z "${SDKMANAGER}" ] + then + echo "No sdkmanager found" + exit 1 + fi + + $SDKMANAGER "$ANDROID_SDK_MANAGER_PARAMETERS" echo "Updated Android SDK." else echo "Not updating Android SDK." diff --git a/dist/platforms/windows/activate.ps1 b/dist/platforms/windows/activate.ps1 index 0022dee3..bfaef5c0 100644 --- a/dist/platforms/windows/activate.ps1 +++ b/dist/platforms/windows/activate.ps1 @@ -1,7 +1,14 @@ # Activates Unity -& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -batchmode -quit -nographics ` - -username $Env:UNITY_EMAIL ` - -password $Env:UNITY_PASSWORD ` - -serial $Env:UNITY_SERIAL ` - -projectPath "c:/BlankProject" ` - -logfile | Out-Host + +Write-Output "" +Write-Output "###########################" +Write-Output "# Activating #" +Write-Output "###########################" +Write-Output "" + +& "$Env:UNITY_PATH/Editor/Unity.exe" -batchmode -quit -nographics ` + -username $Env:UNITY_EMAIL ` + -password $Env:UNITY_PASSWORD ` + -serial $Env:UNITY_SERIAL ` + -projectPath "c:/BlankProject" ` + -logfile - | Out-Host diff --git a/dist/platforms/windows/build.ps1 b/dist/platforms/windows/build.ps1 index 50ae2795..e8727618 100644 --- a/dist/platforms/windows/build.ps1 +++ b/dist/platforms/windows/build.ps1 @@ -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 # @@ -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 -& "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 +# Remove null items as that will fail the Start-Process call +$unityArgs = $unityArgs | Where-Object { $_ -ne $null } -# Catch exit code -$Env:BUILD_EXIT_CODE=$LastExitCode +$process = Start-Process -FilePath "$Env:UNITY_PATH\Editor\Unity.exe" ` + -ArgumentList $unityArgs ` + -PassThru ` + -NoNewWindow -# 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)$('"')" +while (!$process.HasExited) { + if ($process.HasExited) { + Start-Sleep -Seconds 5 + 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 + } + + 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 "" diff --git a/dist/platforms/windows/entrypoint.ps1 b/dist/platforms/windows/entrypoint.ps1 index f0a6b555..f156863d 100644 --- a/dist/platforms/windows/entrypoint.ps1 +++ b/dist/platforms/windows/entrypoint.ps1 @@ -1,10 +1,16 @@ +Get-Process +Start-Sleep -Seconds 3 + # 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" @@ -16,3 +22,6 @@ regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio. # Free the seat for the activated license & "c:\steps\return_license.ps1" + +Start-Sleep -Seconds 3 +Get-Process diff --git a/dist/platforms/windows/return_license.ps1 b/dist/platforms/windows/return_license.ps1 index a60c1a1b..709c3895 100644 --- a/dist/platforms/windows/return_license.ps1 +++ b/dist/platforms/windows/return_license.ps1 @@ -1,7 +1,14 @@ # Return the active Unity license -& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -batchmode -quit -nographics ` - -username $Env:UNITY_EMAIL ` - -password $Env:UNITY_PASSWORD ` - -returnlicense ` - -projectPath "c:/BlankProject" ` - -logfile | Out-Host + +Write-Output "" +Write-Output "###########################" +Write-Output "# Return License #" +Write-Output "###########################" +Write-Output "" + +& "$Env:UNITY_PATH\Editor\Unity.exe" -batchmode -quit -nographics ` + -username $Env:UNITY_EMAIL ` + -password $Env:UNITY_PASSWORD ` + -returnlicense ` + -projectPath "c:/BlankProject" ` + -logfile - | Out-Host diff --git a/src/index.ts b/src/index.ts index 3f621d8e..2457eb1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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()); @@ -38,4 +42,5 @@ async function runMain() { core.setFailed((error as Error).message); } } + runMain(); diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index bd5f9103..8c322124 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -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; @@ -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 { @@ -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, diff --git a/src/model/docker.ts b/src/model/docker.ts index 24b93ab5..aec955bc 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -48,6 +48,8 @@ class Docker { sshPublicKeysDirectoryPath, gitPrivateToken, dockerWorkspacePath, + dockerCpuLimit, + dockerMemoryLimit, } = parameters; const githubHome = path.join(runnerTempPath, '_github_home'); @@ -72,6 +74,8 @@ class Docker { --volume "${actionFolder}/platforms/ubuntu/steps:/steps:z" \ --volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \ --volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \ + --cpus=${dockerCpuLimit} \ + --memory=${dockerMemoryLimit} \ ${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \ ${ sshAgent && !sshPublicKeysDirectoryPath @@ -86,7 +90,16 @@ class Docker { } static getWindowsCommand(image: string, parameters: DockerParameters): string { - const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath } = parameters; + const { + workspace, + actionFolder, + unitySerial, + gitPrivateToken, + dockerWorkspacePath, + dockerCpuLimit, + dockerMemoryLimit, + dockerIsolationMode, + } = parameters; return `docker run \ --workdir c:${dockerWorkspacePath} \ @@ -97,12 +110,16 @@ 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} \ + --isolation=${dockerIsolationMode} \ ${image} \ powershell c:/steps/entrypoint.ps1`; } diff --git a/src/model/image-tag.test.ts b/src/model/image-tag.test.ts index a80fe6bb..77934e5d 100644 --- a/src/model/image-tag.test.ts +++ b/src/model/image-tag.test.ts @@ -30,7 +30,11 @@ describe('ImageTag', () => { test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', (version) => { expect( - () => new ImageTag({ editorVersion: version, targetPlatform: testImageParameters.targetPlatform }), + () => + new ImageTag({ + editorVersion: version, + targetPlatform: testImageParameters.targetPlatform, + }), ).not.toThrow(); }); @@ -46,13 +50,16 @@ describe('ImageTag', () => { describe('toString', () => { it('returns the correct version', () => { - const image = new ImageTag({ editorVersion: '2099.1.1111', targetPlatform: testImageParameters.targetPlatform }); + const image = new ImageTag({ + editorVersion: '2099.1.1111', + targetPlatform: testImageParameters.targetPlatform, + }); switch (process.platform) { case 'win32': - expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111-3`); break; case 'linux': - expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-3`); break; } }); @@ -67,27 +74,33 @@ describe('ImageTag', () => { }); it('returns the specific build platform', () => { - const image = new ImageTag({ editorVersion: '2019.2.11f1', targetPlatform: 'WebGL' }); + const image = new ImageTag({ + editorVersion: '2019.2.11f1', + targetPlatform: 'WebGL', + }); switch (process.platform) { case 'win32': - expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2019.2.11f1-webgl-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2019.2.11f1-webgl-3`); break; case 'linux': - expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-webgl-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-webgl-3`); break; } }); it('returns no specific build platform for generic targetPlatforms', () => { - const image = new ImageTag({ editorVersion: '2019.2.11f1', targetPlatform: 'NoTarget' }); + const image = new ImageTag({ + editorVersion: '2019.2.11f1', + targetPlatform: 'NoTarget', + }); switch (process.platform) { case 'win32': - expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2019.2.11f1-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2019.2.11f1-3`); break; case 'linux': - expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-2`); + expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-3`); break; } }); diff --git a/src/model/image-tag.ts b/src/model/image-tag.ts index 693b84b7..35b4bbeb 100644 --- a/src/model/image-tag.ts +++ b/src/model/image-tag.ts @@ -33,7 +33,7 @@ class ImageTag { this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes( isCloudRunnerLocal ? process.platform : cloudRunnerBuilderPlatform, ); - this.imageRollingVersion = 2; // Will automatically roll to the latest non-breaking version. + this.imageRollingVersion = 3; // Will automatically roll to the latest non-breaking version. } static get versionPattern(): RegExp { @@ -86,8 +86,10 @@ class ImageTag { if (major >= 2020 || (major === 2019 && minor >= 3)) { return windowsIl2cpp; } else { - throw new Error(`Windows-based builds are only supported on 2019.3.X+ versions of Unity. - If you are trying to build for windows-mono, please use a Linux based OS.`); + throw new Error( + `Windows-based builds are only supported on 2019.3.X+ versions of Unity. + If you are trying to build for windows-mono, please use a Linux based OS.`, + ); } } diff --git a/src/model/input.ts b/src/model/input.ts index f50b0633..94a0f2b4 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,35 @@ 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 bytesInMegabyte = 1024 * 1024; + + let memoryMultiplier; + switch (os.platform()) { + case 'linux': + memoryMultiplier = 0.95; + break; + case 'win32': + memoryMultiplier = 0.8; + break; + default: + memoryMultiplier = 0.75; + break; + } + + return ( + Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m` + ); + } + + static get dockerIsolationMode(): string { + return Input.getInput('dockerIsolationMode') || 'default'; + } + public static ToEnvVarFormat(input: string) { if (input.toUpperCase() === input) { return input;