| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | import AWSBuildPlatform from './aws-build-platform'; | 
					
						
							|  |  |  | import * as core from '@actions/core'; | 
					
						
							|  |  |  | import { BuildParameters } from '..'; | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  | import CloudRunnerNamespace from './cloud-runner-namespace'; | 
					
						
							|  |  |  | import CloudRunnerSecret from './cloud-runner-secret'; | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  | import { CloudRunnerProviderInterface } from './cloud-runner-provider-interface'; | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | import Kubernetes from './kubernetes-build-platform'; | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  | import CloudRunnerEnvironmentVariable from './cloud-runner-environment-variable'; | 
					
						
							| 
									
										
										
										
											2021-08-15 18:06:54 +00:00
										 |  |  | import ImageEnvironmentFactory from '../image-environment-factory'; | 
					
						
							| 
									
										
										
										
											2021-08-15 21:03:29 +00:00
										 |  |  | import YAML from 'yaml'; | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | const repositoryFolder = 'repo'; | 
					
						
							|  |  |  | const buildVolumeFolder = 'data'; | 
					
						
							|  |  |  | const cacheFolder = 'cache'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  | class CloudRunner { | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |   static CloudRunnerProviderPlatform: CloudRunnerProviderInterface; | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |   private static buildParams: BuildParameters; | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |   private static defaultSecrets: CloudRunnerSecret[]; | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |   private static buildGuid: string; | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |   private static branchName: string; | 
					
						
							|  |  |  |   private static buildPathFull: string; | 
					
						
							|  |  |  |   private static builderPathFull: string; | 
					
						
							|  |  |  |   private static steamPathFull: string; | 
					
						
							|  |  |  |   private static repoPathFull: string; | 
					
						
							|  |  |  |   private static projectPathFull: string; | 
					
						
							|  |  |  |   private static libraryFolderFull: string; | 
					
						
							| 
									
										
										
										
											2021-08-15 21:32:43 +00:00
										 |  |  |   private static cacheFolderFull: string; | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |   private static lfsDirectory: string; | 
					
						
							|  |  |  |   private static testLFSFile: string; | 
					
						
							|  |  |  |   private static purgeRemoteCaching: boolean; | 
					
						
							|  |  |  |   private static CloudRunnerBranch: string; | 
					
						
							|  |  |  |   private static unityBuilderRepoUrl: string; | 
					
						
							|  |  |  |   private static targetBuildRepoUrl: string; | 
					
						
							|  |  |  |   private static SteamDeploy: boolean = process.env.STEAM_DEPLOY !== undefined || false; | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |   private static readonly defaultGitShaEnvironmentVariable = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'GITHUB_SHA', | 
					
						
							|  |  |  |       value: process.env.GITHUB_SHA || '', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static async build(buildParameters: BuildParameters, baseImage) { | 
					
						
							| 
									
										
										
										
											2021-08-15 21:21:47 +00:00
										 |  |  |     const t = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     CloudRunner.buildGuid = CloudRunnerNamespace.generateBuildName( | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       CloudRunner.readRunNumber(), | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       buildParameters.platform, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |     CloudRunner.buildParams = buildParameters; | 
					
						
							|  |  |  |     CloudRunner.setupBranchName(); | 
					
						
							|  |  |  |     CloudRunner.setupFolderVariables(); | 
					
						
							|  |  |  |     CloudRunner.setupDefaultSecrets(); | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       CloudRunner.setupBuildPlatform(); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |       await this.CloudRunnerProviderPlatform.setupSharedBuildResources( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |         this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |         this.buildParams, | 
					
						
							|  |  |  |         this.branchName, | 
					
						
							|  |  |  |         this.defaultSecrets, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       await CloudRunner.SetupStep(); | 
					
						
							| 
									
										
										
										
											2021-08-15 21:21:47 +00:00
										 |  |  |       const t2 = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-08-15 23:13:50 +00:00
										 |  |  |       core.info(`Setup time: ${Math.floor((t2 - t) / 1000)}s`); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       await CloudRunner.BuildStep(baseImage); | 
					
						
							| 
									
										
										
										
											2021-08-15 21:21:47 +00:00
										 |  |  |       const t3 = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-08-15 23:13:50 +00:00
										 |  |  |       core.info(`Build time: ${Math.floor((t3 - t2) / 1000)}s`); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       await CloudRunner.CompressionStep(); | 
					
						
							| 
									
										
										
										
											2021-08-15 21:03:29 +00:00
										 |  |  |       core.info(`Post build steps ${this.buildParams.postBuildSteps}`); | 
					
						
							|  |  |  |       this.buildParams.postBuildSteps = YAML.parse(this.buildParams.postBuildSteps); | 
					
						
							| 
									
										
										
										
											2021-08-15 20:45:22 +00:00
										 |  |  |       core.info(`Post build steps ${JSON.stringify(this.buildParams.postBuildSteps, undefined, 4)}`); | 
					
						
							|  |  |  |       for (const step of this.buildParams.postBuildSteps) { | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         const stepSecrets: CloudRunnerSecret[] = step.secrets.map((x) => { | 
					
						
							|  |  |  |           const secret: CloudRunnerSecret = { | 
					
						
							| 
									
										
										
										
											2021-08-15 22:12:45 +00:00
										 |  |  |             ParameterKey: x.name, | 
					
						
							|  |  |  |             EnvironmentVariable: x.name, | 
					
						
							|  |  |  |             ParameterValue: x.value, | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |           return secret; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         await this.CloudRunnerProviderPlatform.runBuildTask( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |           this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-15 20:45:22 +00:00
										 |  |  |           step['image'], | 
					
						
							|  |  |  |           step['commands'], | 
					
						
							|  |  |  |           `/${buildVolumeFolder}`, | 
					
						
							|  |  |  |           `/${buildVolumeFolder}`, | 
					
						
							|  |  |  |           [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               name: 'GITHUB_SHA', | 
					
						
							|  |  |  |               value: process.env.GITHUB_SHA || '', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2021-08-15 22:12:45 +00:00
										 |  |  |           [...this.defaultSecrets, ...stepSecrets], | 
					
						
							| 
									
										
										
										
											2021-08-15 20:45:22 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |       await this.CloudRunnerProviderPlatform.cleanupSharedBuildResources( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |         this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |         this.buildParams, | 
					
						
							|  |  |  |         this.branchName, | 
					
						
							|  |  |  |         this.defaultSecrets, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       await CloudRunner.handleException(error); | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       throw error; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-15 14:23:18 +00:00
										 |  |  |   private static setupFolderVariables() { | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |     this.buildPathFull = `/${buildVolumeFolder}/${this.buildGuid}`; | 
					
						
							| 
									
										
										
										
											2021-08-15 14:23:18 +00:00
										 |  |  |     this.builderPathFull = `${this.buildPathFull}/builder`; | 
					
						
							|  |  |  |     this.steamPathFull = `${this.buildPathFull}/steam`; | 
					
						
							|  |  |  |     this.repoPathFull = `${this.buildPathFull}/${repositoryFolder}`; | 
					
						
							|  |  |  |     this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`; | 
					
						
							|  |  |  |     this.libraryFolderFull = `${this.projectPathFull}/Library`; | 
					
						
							| 
									
										
										
										
											2021-08-15 21:32:43 +00:00
										 |  |  |     this.cacheFolderFull = `/${buildVolumeFolder}/${cacheFolder}/${this.branchName}`; | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |     this.lfsDirectory = `${this.repoPathFull}/.git/lfs`; | 
					
						
							|  |  |  |     this.testLFSFile = `${this.projectPathFull}/Assets/LFS_Test_File.jpg`; | 
					
						
							|  |  |  |     this.purgeRemoteCaching = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined; | 
					
						
							|  |  |  |     this.CloudRunnerBranch = process.env.CloudRunnerBranch ? `--branch "${process.env.CloudRunnerBranch}"` : ''; | 
					
						
							|  |  |  |     this.unityBuilderRepoUrl = `https://${this.buildParams.githubToken}@github.com/game-ci/unity-builder.git`; | 
					
						
							|  |  |  |     this.targetBuildRepoUrl = `https://${this.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`; | 
					
						
							| 
									
										
										
										
											2021-08-15 14:23:18 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |   private static getHandleCachingCommand() { | 
					
						
							|  |  |  |     return `${this.builderPathFull}/dist/cloud-runner/handleCaching.sh "${this.cacheFolderFull}" "${this.libraryFolderFull}" "${this.lfsDirectory}" "${this.purgeRemoteCaching}"`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |   private static getCloneNoLFSCommand() { | 
					
						
							|  |  |  |     return `${this.builderPathFull}/dist/cloud-runner/cloneNoLFS.sh "${this.repoPathFull}" "${this.targetBuildRepoUrl}" "${this.testLFSFile}"`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |   private static getCloneBuilder() { | 
					
						
							|  |  |  |     return `git clone -q ${this.CloudRunnerBranch} ${this.unityBuilderRepoUrl} ${this.builderPathFull}`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |   private static async SetupStep() { | 
					
						
							|  |  |  |     core.info('Starting step 1/4 clone and restore cache)'); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     await this.CloudRunnerProviderPlatform.runBuildTask( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |       this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       'alpine/git', | 
					
						
							|  |  |  |       [ | 
					
						
							| 
									
										
										
										
											2021-08-13 20:09:01 +00:00
										 |  |  |         ` printenv
 | 
					
						
							|  |  |  |           apk update -q | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |           apk add unzip zip git-lfs jq tree -q | 
					
						
							| 
									
										
										
										
											2021-08-02 00:43:14 +00:00
										 |  |  |           mkdir -p ${this.buildPathFull} | 
					
						
							|  |  |  |           mkdir -p ${this.builderPathFull} | 
					
						
							|  |  |  |           mkdir -p ${this.repoPathFull} | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |           ${this.getCloneBuilder()} | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |           echo ' ' | 
					
						
							|  |  |  |           echo 'Initializing source repository for cloning with caching of LFS files' | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |           ${this.getCloneNoLFSCommand()} | 
					
						
							| 
									
										
										
										
											2021-08-15 23:29:06 +00:00
										 |  |  |           echo 'Source repository initialized' | 
					
						
							|  |  |  |           echo ' ' | 
					
						
							| 
									
										
										
										
											2021-08-15 19:07:02 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo $LFS_ASSETS_HASH | 
					
						
							| 
									
										
										
										
											2021-08-15 15:26:12 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo 'Large File before LFS caching and pull' | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}" | 
					
						
							| 
									
										
										
										
											2021-08-15 15:26:12 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo ' ' | 
					
						
							| 
									
										
										
										
											2021-08-15 15:45:04 +00:00
										 |  |  |           echo 'Starting checks of cache for the Unity project Library and git LFS files' | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |           ${this.getHandleCachingCommand()} | 
					
						
							| 
									
										
										
										
											2021-08-15 15:26:12 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo 'Caching complete' | 
					
						
							|  |  |  |           ${process.env.DEBUG ? '' : '#'}echo ' ' | 
					
						
							|  |  |  |           ${process.env.DEBUG ? '' : '#'}echo 'Large File after LFS caching and pull' | 
					
						
							| 
									
										
										
										
											2021-08-21 19:01:53 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}" | 
					
						
							| 
									
										
										
										
											2021-08-15 23:29:06 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo ' ' | 
					
						
							| 
									
										
										
										
											2021-08-15 15:26:12 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}" | 
					
						
							| 
									
										
										
										
											2021-08-15 15:45:04 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}" | 
					
						
							| 
									
										
										
										
											2021-08-15 23:29:06 +00:00
										 |  |  |           ${process.env.DEBUG ? '' : '#'}echo ' ' | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       `,
 | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       `/${buildVolumeFolder}`, | 
					
						
							|  |  |  |       `/${buildVolumeFolder}/`, | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       CloudRunner.defaultGitShaEnvironmentVariable, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       this.defaultSecrets, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static async BuildStep(baseImage: any) { | 
					
						
							|  |  |  |     core.info('Starting part 2/4 (build unity project)'); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     await this.CloudRunnerProviderPlatform.runBuildTask( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |       this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       baseImage.toString(), | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         `
 | 
					
						
							| 
									
										
										
										
											2021-08-15 04:41:24 +00:00
										 |  |  |             printenv | 
					
						
							| 
									
										
										
										
											2021-08-17 16:47:17 +00:00
										 |  |  |             export GITHUB_WORKSPACE="${this.repoPathFull}" | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |             cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction" | 
					
						
							|  |  |  |             cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh" | 
					
						
							|  |  |  |             cp -r "${this.builderPathFull}/dist/steps/" "/steps" | 
					
						
							|  |  |  |             chmod -R +x "/entrypoint.sh" | 
					
						
							|  |  |  |             chmod -R +x "/steps" | 
					
						
							|  |  |  |             /entrypoint.sh | 
					
						
							| 
									
										
										
										
											2021-08-17 10:43:23 +00:00
										 |  |  |             ${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}" | 
					
						
							|  |  |  |             ${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}" | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |           `,
 | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       `/${buildVolumeFolder}`, | 
					
						
							| 
									
										
										
										
											2021-08-15 15:34:16 +00:00
										 |  |  |       `/${this.projectPathFull}`, | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  |       CloudRunner.readBuildEnvironmentVariables(), | 
					
						
							| 
									
										
										
										
											2021-08-15 19:00:31 +00:00
										 |  |  |       this.defaultSecrets, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static async CompressionStep() { | 
					
						
							|  |  |  |     core.info('Starting step 3/4 build compression'); | 
					
						
							|  |  |  |     // Cleanup
 | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     await this.CloudRunnerProviderPlatform.runBuildTask( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |       this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       'alpine', | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         `
 | 
					
						
							| 
									
										
										
										
											2021-08-15 19:23:52 +00:00
										 |  |  |             printenv | 
					
						
							| 
									
										
										
										
											2021-08-17 14:03:06 +00:00
										 |  |  |             apk update -q | 
					
						
							|  |  |  |             apk add zip tree -q | 
					
						
							| 
									
										
										
										
											2021-08-17 16:50:05 +00:00
										 |  |  |             ${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull" | 
					
						
							|  |  |  |             ${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull" | 
					
						
							| 
									
										
										
										
											2021-08-21 05:01:15 +00:00
										 |  |  |             cd "$libraryFolderFull/.." | 
					
						
							|  |  |  |             zip -r "lib-$BUILDID.zip" "./Library" | 
					
						
							| 
									
										
										
										
											2021-08-20 03:15:09 +00:00
										 |  |  |             mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib" | 
					
						
							| 
									
										
										
										
											2021-08-17 16:50:05 +00:00
										 |  |  |             cd "$repoPathFull" | 
					
						
							|  |  |  |             ls -lh "$repoPathFull" | 
					
						
							| 
									
										
										
										
											2021-08-21 05:01:15 +00:00
										 |  |  |             zip -r "build-$BUILDID.zip" "./${CloudRunner.buildParams.buildPath}" | 
					
						
							| 
									
										
										
										
											2021-08-17 16:50:05 +00:00
										 |  |  |             mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip" | 
					
						
							| 
									
										
										
										
											2021-08-20 03:15:09 +00:00
										 |  |  |             ${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull" | 
					
						
							|  |  |  |             ${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull/.." | 
					
						
							| 
									
										
										
										
											2021-08-17 16:50:05 +00:00
										 |  |  |             ${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull" | 
					
						
							|  |  |  |             ${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull" | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |           `,
 | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       `/${buildVolumeFolder}`, | 
					
						
							|  |  |  |       `/${buildVolumeFolder}`, | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           name: 'GITHUB_SHA', | 
					
						
							|  |  |  |           value: process.env.GITHUB_SHA || '', | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-08-20 03:50:45 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |           name: 'cacheFolderFull', | 
					
						
							|  |  |  |           value: this.cacheFolderFull, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       ], | 
					
						
							|  |  |  |       this.defaultSecrets, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     core.info('compression step complete'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static setupBuildPlatform() { | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     switch (this.buildParams.cloudRunnerCluster) { | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       case 'aws': | 
					
						
							|  |  |  |         core.info('Building with AWS'); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         this.CloudRunnerProviderPlatform = new AWSBuildPlatform(this.buildParams); | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |       case 'k8s': | 
					
						
							|  |  |  |         core.info('Building with Kubernetes'); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         this.CloudRunnerProviderPlatform = new Kubernetes(this.buildParams); | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static readRunNumber() { | 
					
						
							|  |  |  |     const runNumber = process.env.GITHUB_RUN_NUMBER; | 
					
						
							|  |  |  |     if (!runNumber || runNumber === '') { | 
					
						
							|  |  |  |       throw new Error('no run number found, exiting'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return runNumber; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-15 14:23:18 +00:00
										 |  |  |   private static setupBranchName() { | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     const defaultBranchName = | 
					
						
							|  |  |  |       process.env.GITHUB_REF?.split('/') | 
					
						
							|  |  |  |         .filter((x) => { | 
					
						
							|  |  |  |           x = x[0].toUpperCase() + x.slice(1); | 
					
						
							|  |  |  |           return x; | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         .join('') || ''; | 
					
						
							|  |  |  |     this.branchName = | 
					
						
							|  |  |  |       process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-15 14:23:18 +00:00
										 |  |  |   private static setupDefaultSecrets() { | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     this.defaultSecrets = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'GithubToken', | 
					
						
							|  |  |  |         EnvironmentVariable: 'GITHUB_TOKEN', | 
					
						
							|  |  |  |         ParameterValue: this.buildParams.githubToken, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-08-15 13:46:18 +00:00
										 |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'branch', | 
					
						
							|  |  |  |         EnvironmentVariable: 'branch', | 
					
						
							|  |  |  |         ParameterValue: this.branchName, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-08-15 13:58:44 +00:00
										 |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'buildPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'buildPathFull', | 
					
						
							|  |  |  |         ParameterValue: this.buildPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'projectPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'projectPathFull', | 
					
						
							|  |  |  |         ParameterValue: this.projectPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-08-15 15:01:15 +00:00
										 |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'libraryFolderFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'libraryFolderFull', | 
					
						
							|  |  |  |         ParameterValue: this.libraryFolderFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'builderPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'builderPathFull', | 
					
						
							|  |  |  |         ParameterValue: this.builderPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'repoPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'repoPathFull', | 
					
						
							|  |  |  |         ParameterValue: this.repoPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'steamPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'steamPathFull', | 
					
						
							|  |  |  |         ParameterValue: this.steamPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2021-08-15 18:06:54 +00:00
										 |  |  |     this.defaultSecrets.push( | 
					
						
							|  |  |  |       ...ImageEnvironmentFactory.getEnvironmentVariables(this.buildParams).map((x) => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           ParameterKey: x.name, | 
					
						
							|  |  |  |           EnvironmentVariable: x.name, | 
					
						
							|  |  |  |           ParameterValue: x.value, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |   private static readBuildEnvironmentVariables(): CloudRunnerEnvironmentVariable[] { | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |     return [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ContainerMemory', | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         value: this.buildParams.cloudRunnerMemory, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ContainerCpu', | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |         value: this.buildParams.cloudRunnerCpu, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'GITHUB_WORKSPACE', | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |         value: `/${buildVolumeFolder}/${this.buildGuid}/${repositoryFolder}/`, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'PROJECT_PATH', | 
					
						
							|  |  |  |         value: this.buildParams.projectPath, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_PATH', | 
					
						
							|  |  |  |         value: this.buildParams.buildPath, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_FILE', | 
					
						
							|  |  |  |         value: this.buildParams.buildFile, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_NAME', | 
					
						
							|  |  |  |         value: this.buildParams.buildName, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_METHOD', | 
					
						
							|  |  |  |         value: this.buildParams.buildMethod, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'CUSTOM_PARAMETERS', | 
					
						
							|  |  |  |         value: this.buildParams.customParameters, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_TARGET', | 
					
						
							|  |  |  |         value: this.buildParams.platform, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ANDROID_VERSION_CODE', | 
					
						
							|  |  |  |         value: this.buildParams.androidVersionCode.toString(), | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ANDROID_KEYSTORE_NAME', | 
					
						
							|  |  |  |         value: this.buildParams.androidKeystoreName, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ANDROID_KEYALIAS_NAME', | 
					
						
							|  |  |  |         value: this.buildParams.androidKeyaliasName, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static readUploadArtifactEnvironmentVariables() { | 
					
						
							|  |  |  |     return [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'GITHUB_SHA', | 
					
						
							|  |  |  |         value: process.env.GITHUB_SHA || '', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'AWS_DEFAULT_REGION', | 
					
						
							|  |  |  |         value: process.env.AWS_DEFAULT_REGION || '', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static async handleException(error: unknown) { | 
					
						
							|  |  |  |     core.error(JSON.stringify(error, undefined, 4)); | 
					
						
							|  |  |  |     core.setFailed('Remote Builder failed'); | 
					
						
							| 
									
										
										
										
											2021-08-17 22:13:46 +00:00
										 |  |  |     await this.CloudRunnerProviderPlatform.cleanupSharedBuildResources( | 
					
						
							| 
									
										
										
										
											2021-08-15 21:59:58 +00:00
										 |  |  |       this.buildGuid, | 
					
						
							| 
									
										
										
										
											2021-08-01 23:43:20 +00:00
										 |  |  |       this.buildParams, | 
					
						
							|  |  |  |       this.branchName, | 
					
						
							|  |  |  |       this.defaultSecrets, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-08-17 20:09:42 +00:00
										 |  |  | export default CloudRunner; |