diff --git a/action.yml b/action.yml index 09f95e08..0ade5fcb 100644 --- a/action.yml +++ b/action.yml @@ -253,6 +253,10 @@ inputs: description: 'The path to mount the workspace inside the docker container. For windows, leave out the drive letter. For example c:/github/workspace should be defined as /github/workspace' + skipActivation: + default: 'false' + required: false + description: 'Skip the activation/deactivation of Unity. This assumes Unity is already activated.' outputs: volume: diff --git a/dist/index.js b/dist/index.js index bde8c763..d02d86ce 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 c86b6465..7b680bb4 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/dist/licenses.txt b/dist/licenses.txt index d21d19f2..5237d704 100644 Binary files a/dist/licenses.txt and b/dist/licenses.txt differ diff --git a/dist/platforms/mac/entrypoint.sh b/dist/platforms/mac/entrypoint.sh index bea8f36a..90819bbe 100755 --- a/dist/platforms/mac/entrypoint.sh +++ b/dist/platforms/mac/entrypoint.sh @@ -1,32 +1,40 @@ #!/usr/bin/env bash # -# Create directories for license activation +# Perform Activation # -UNITY_LICENSE_PATH="/Library/Application Support/Unity" +if [ "$SKIP_ACTIVATION" != "true" ]; then + UNITY_LICENSE_PATH="/Library/Application Support/Unity" -if [ ! -d "$UNITY_LICENSE_PATH" ]; then - echo "Creating Unity License Directory" - sudo mkdir -p "$UNITY_LICENSE_PATH" - sudo chmod -R 777 "$UNITY_LICENSE_PATH" -fi; + if [ ! -d "$UNITY_LICENSE_PATH" ]; then + echo "Creating Unity License Directory" + sudo mkdir -p "$UNITY_LICENSE_PATH" + sudo chmod -R 777 "$UNITY_LICENSE_PATH" + fi; -ACTIVATE_LICENSE_PATH="$ACTION_FOLDER/BlankProject" -mkdir -p "$ACTIVATE_LICENSE_PATH" + ACTIVATE_LICENSE_PATH="$ACTION_FOLDER/BlankProject" + mkdir -p "$ACTIVATE_LICENSE_PATH" + + source $ACTION_FOLDER/platforms/mac/steps/activate.sh +else + echo "Skipping activation" +fi # -# Run steps +# Run Build # -source $ACTION_FOLDER/platforms/mac/steps/activate.sh + source $ACTION_FOLDER/platforms/mac/steps/build.sh -source $ACTION_FOLDER/platforms/mac/steps/return_license.sh # -# Remove license activation directory +# License Cleanup # -rm -r "$ACTIVATE_LICENSE_PATH" +if [ "$SKIP_ACTIVATION" != "true" ]; then + source $ACTION_FOLDER/platforms/mac/steps/return_license.sh + rm -r "$ACTIVATE_LICENSE_PATH" +fi # # Instructions for debugging diff --git a/dist/platforms/ubuntu/steps/runsteps.sh b/dist/platforms/ubuntu/steps/runsteps.sh index e8376051..adfd584b 100644 --- a/dist/platforms/ubuntu/steps/runsteps.sh +++ b/dist/platforms/ubuntu/steps/runsteps.sh @@ -5,15 +5,23 @@ # source /steps/set_extra_git_configs.sh source /steps/set_gitcredential.sh -source /steps/activate.sh -# If we didn't activate successfully, exit with the exit code from the activation step. -if [[ $UNITY_EXIT_CODE -ne 0 ]]; then - exit $UNITY_EXIT_CODE +if [ "$SKIP_ACTIVATION" != "true" ]; then + source /steps/activate.sh + + # If we didn't activate successfully, exit with the exit code from the activation step. + if [[ $UNITY_EXIT_CODE -ne 0 ]]; then + exit $UNITY_EXIT_CODE + fi +else + echo "Skipping activation" fi source /steps/build.sh -source /steps/return_license.sh + +if [ "$SKIP_ACTIVATION" != "true" ]; then + source /steps/return_license.sh +fi # # Instructions for debugging diff --git a/dist/platforms/windows/entrypoint.ps1 b/dist/platforms/windows/entrypoint.ps1 index fac75b74..4d7057e6 100644 --- a/dist/platforms/windows/entrypoint.ps1 +++ b/dist/platforms/windows/entrypoint.ps1 @@ -2,7 +2,7 @@ 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-Object {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 @@ -14,18 +14,25 @@ Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force } . "c:\steps\set_gitcredential.ps1" # Activate Unity -. "c:\steps\activate.ps1" +if ($env:SKIP_ACTIVATION -ne "true") { + . "c:\steps\activate.ps1" -# If we didn't activate successfully, exit with the exit code from the activation step. -if ($ACTIVATION_EXIT_CODE -ne 0) { + # If we didn't activate successfully, exit with the exit code from the activation step. + if ($ACTIVATION_EXIT_CODE -ne 0) { exit $ACTIVATION_EXIT_CODE + } +} +else { + Write-Host "Skipping activation" } # Build the project . "c:\steps\build.ps1" # Free the seat for the activated license -. "c:\steps\return_license.ps1" +if ($env:SKIP_ACTIVATION -ne "true") { + . "c:\steps\return_license.ps1" +} Get-Process diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index 6710a4da..60e27bd6 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -22,6 +22,7 @@ class BuildParameters { public customImage!: string; public unitySerial!: string; public unityLicensingServer!: string; + public skipActivation!: string; public runnerTempPath!: string; public targetPlatform!: string; public projectPath!: string; @@ -59,7 +60,7 @@ class BuildParameters { public kubeVolumeSize!: string; public kubeVolume!: string; public kubeStorageClass!: string; - public runAsHostUser!: String; + public runAsHostUser!: string; public chownFilesTo!: string; public commandHooks!: string; public pullInputList!: string[]; @@ -146,6 +147,7 @@ class BuildParameters { customImage: Input.customImage, unitySerial, unityLicensingServer: Input.unityLicensingServer, + skipActivation: Input.skipActivation, runnerTempPath: Input.runnerTempPath, targetPlatform: Input.targetPlatform, projectPath: Input.projectPath, @@ -168,7 +170,7 @@ class BuildParameters { customParameters: Input.customParameters, sshAgent: Input.sshAgent, sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath, - gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), + gitPrivateToken: Input.gitPrivateToken ?? (await GithubCliReader.GetGitHubAuthToken()), runAsHostUser: Input.runAsHostUser, chownFilesTo: Input.chownFilesTo, dockerCpuLimit: Input.dockerCpuLimit, @@ -187,10 +189,10 @@ class BuildParameters { preBuildContainerHooks: CloudRunnerOptions.preBuildContainerHooks, customJob: CloudRunnerOptions.customJob, runNumber: Input.runNumber, - branch: Input.branch.replace('/head', '') || (await GitRepoReader.GetBranch()), + branch: Input.branch.replaceAll('/head', '') || (await GitRepoReader.GetBranch()), cloudRunnerBranch: CloudRunnerOptions.cloudRunnerBranch.split('/').reverse()[0], cloudRunnerDebug: CloudRunnerOptions.cloudRunnerDebug, - githubRepo: Input.githubRepo || (await GitRepoReader.GetRemote()) || 'game-ci/unity-builder', + githubRepo: (Input.githubRepo ?? (await GitRepoReader.GetRemote())) || 'game-ci/unity-builder', isCliMode: Cli.isCliMode, awsStackName: CloudRunnerOptions.awsStackName, gitSha: Input.gitSha, diff --git a/src/model/image-environment-factory.ts b/src/model/image-environment-factory.ts index 2df52f1a..0952c7d7 100644 --- a/src/model/image-environment-factory.ts +++ b/src/model/image-environment-factory.ts @@ -29,6 +29,7 @@ class ImageEnvironmentFactory { name: 'UNITY_LICENSING_SERVER', value: parameters.unityLicensingServer, }, + { name: 'SKIP_ACTIVATION', value: parameters.skipActivation }, { name: 'UNITY_VERSION', value: parameters.editorVersion }, { name: 'USYM_UPLOAD_AUTH_TOKEN', @@ -81,20 +82,12 @@ class ImageEnvironmentFactory { ]; if (parameters.providerStrategy === 'local-docker') { for (const element of additionalVariables) { - if ( - environmentVariables.find( - (x) => element !== undefined && element.name !== undefined && x.name === element.name, - ) === undefined - ) { + if (environmentVariables.some((x) => element?.name === x?.name) === undefined) { environmentVariables.push(element); } } for (const variable of environmentVariables) { - if ( - environmentVariables.find( - (x) => variable !== undefined && variable.name !== undefined && x.name === variable.name, - ) === undefined - ) { + if (!environmentVariables.some((x) => variable?.name === x?.name)) { environmentVariables = environmentVariables.filter((x) => x !== variable); } } diff --git a/src/model/input.ts b/src/model/input.ts index 4d2ea09f..4eb18bcc 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -55,7 +55,7 @@ class Input { static get branch(): string { if (Input.getInput(`GITHUB_REF`)) { - return Input.getInput(`GITHUB_REF`)!.replace('refs/', '').replace(`head/`, '').replace(`heads/`, ''); + return Input.getInput(`GITHUB_REF`)!.replaceAll('refs/', '').replaceAll(`head/`, '').replaceAll(`heads/`, ''); } else if (Input.getInput('branch')) { return Input.getInput('branch')!; } else { @@ -104,7 +104,7 @@ class Input { rawProjectPath = '.'; } - return rawProjectPath.replace(/\/$/, ''); + return rawProjectPath.replaceAll(/\/$/, ''); } static get runnerTempPath(): string { @@ -186,7 +186,7 @@ class Input { } static get sshPublicKeysDirectoryPath(): string { - return Input.getInput('sshPublicKeysDirectoryPath') || ''; + return Input.getInput('sshPublicKeysDirectoryPath') ?? ''; } static get gitPrivateToken(): string | undefined { @@ -194,27 +194,27 @@ class Input { } static get runAsHostUser(): string { - return Input.getInput('runAsHostUser') || 'false'; + return Input.getInput('runAsHostUser')?.toLowerCase() ?? 'false'; } static get chownFilesTo() { - return Input.getInput('chownFilesTo') || ''; + return Input.getInput('chownFilesTo') ?? ''; } static get allowDirtyBuild(): boolean { - const input = Input.getInput('allowDirtyBuild') || false; + const input = Input.getInput('allowDirtyBuild') ?? false; return input === 'true'; } static get cacheUnityInstallationOnMac(): boolean { - const input = Input.getInput('cacheUnityInstallationOnMac') || false; + const input = Input.getInput('cacheUnityInstallationOnMac') ?? false; return input === 'true'; } static get unityHubVersionOnMac(): string { - const input = Input.getInput('unityHubVersionOnMac') || ''; + const input = Input.getInput('unityHubVersionOnMac') ?? ''; return input !== '' ? input : ''; } @@ -228,11 +228,11 @@ class Input { } static get dockerWorkspacePath(): string { - return Input.getInput('dockerWorkspacePath') || '/github/workspace'; + return Input.getInput('dockerWorkspacePath') ?? '/github/workspace'; } static get dockerCpuLimit(): string { - return Input.getInput('dockerCpuLimit') || os.cpus().length.toString(); + return Input.getInput('dockerCpuLimit') ?? os.cpus().length.toString(); } static get dockerMemoryLimit(): string { @@ -252,20 +252,24 @@ class Input { } return ( - Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m` + Input.getInput('dockerMemoryLimit') ?? `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m` ); } static get dockerIsolationMode(): string { - return Input.getInput('dockerIsolationMode') || 'default'; + return Input.getInput('dockerIsolationMode') ?? 'default'; } static get containerRegistryRepository(): string { - return Input.getInput('containerRegistryRepository') || 'unityci/editor'; + return Input.getInput('containerRegistryRepository') ?? 'unityci/editor'; } static get containerRegistryImageVersion(): string { - return Input.getInput('containerRegistryImageVersion') || '3'; + return Input.getInput('containerRegistryImageVersion') ?? '3'; + } + + static get skipActivation(): string { + return Input.getInput('skipActivation')?.toLowerCase() ?? 'false'; } public static ToEnvVarFormat(input: string) { @@ -274,10 +278,10 @@ class Input { } return input - .replace(/([A-Z])/g, ' $1') + .replaceAll(/([A-Z])/g, ' $1') .trim() .toUpperCase() - .replace(/ /g, '_'); + .replaceAll(' ', '_'); } }