Support cache and input override commands as input + full support custom hooks
							parent
							
								
									dcfc6e50c5
								
							
						
					
					
						commit
						c022d6e656
					
				|  | @ -264,6 +264,7 @@ class BuildParameters { | |||
|             const buildVersion = yield versioning_1.default.determineVersion(input_1.default.versioningStrategy, input_1.default.specifiedVersion); | ||||
|             const androidVersionCode = android_versioning_1.default.determineVersionCode(buildVersion, input_1.default.androidVersionCode); | ||||
|             const androidSdkManagerParameters = android_versioning_1.default.determineSdkManagerParameters(input_1.default.androidTargetSdkVersion); | ||||
|             yield input_1.default.PopulateQueryOverrideInput(); | ||||
|             let unitySerial = ''; | ||||
|             if (!process.env.UNITY_SERIAL) { | ||||
|                 //No serial was present so it is a personal license that we need to convert
 | ||||
|  | @ -306,7 +307,6 @@ class BuildParameters { | |||
|                 cloudRunnerCluster: input_1.default.cloudRunnerCluster, | ||||
|                 awsBaseStackName: input_1.default.awsBaseStackName, | ||||
|                 kubeConfig: input_1.default.kubeConfig, | ||||
|                 githubToken: yield input_1.default.githubToken(), | ||||
|                 cloudRunnerMemory: input_1.default.cloudRunnerMemory, | ||||
|                 cloudRunnerCpu: input_1.default.cloudRunnerCpu, | ||||
|                 kubeVolumeSize: input_1.default.kubeVolumeSize, | ||||
|  | @ -322,6 +322,11 @@ class BuildParameters { | |||
|                 gitSha: input_1.default.gitSha, | ||||
|                 logId: nanoid_1.customAlphabet(cloud_runner_constants_1.default.alphabet, 9)(), | ||||
|                 buildGuid: cloud_runner_namespace_1.default.generateBuildName(input_1.default.runNumber, input_1.default.targetPlatform), | ||||
|                 customJobHooks: input_1.default.customJobHooks(), | ||||
|                 cachePullOverrideCommand: input_1.default.cachePullOverrideCommand(), | ||||
|                 cachePushOverrideCommand: input_1.default.cachePushOverrideCommand(), | ||||
|                 readInputOverrideCommand: input_1.default.readInputOverrideCommand(), | ||||
|                 readInputFromOverrideList: input_1.default.readInputFromOverrideList(), | ||||
|             }; | ||||
|         }); | ||||
|     } | ||||
|  | @ -638,8 +643,8 @@ class Caching { | |||
|                 yield cloud_runner_system_1.CloudRunnerSystem.Run(`zip ${cacheKey}.zip ${path_1.default.basename(sourceFolder)}`); | ||||
|                 console_1.assert(fs_1.default.existsSync(`${cacheKey}.zip`), 'cache zip exists'); | ||||
|                 console_1.assert(fs_1.default.existsSync(path_1.default.basename(sourceFolder)), 'source folder exists'); | ||||
|                 if (process.env.CLOUD_RUNNER_PRE_CACHE_PUSH) { | ||||
|                     cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PUSH)); | ||||
|                 if (cloud_runner_state_1.CloudRunnerState.buildParams.cachePushOverrideCommand) { | ||||
|                     cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(cloud_runner_state_1.CloudRunnerState.buildParams.cachePushOverrideCommand)); | ||||
|                 } | ||||
|                 cloud_runner_system_1.CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`); | ||||
|                 remote_client_logger_1.RemoteClientLogger.log(`moved ${cacheKey}.zip to ${cacheFolder}`); | ||||
|  | @ -679,8 +684,8 @@ class Caching { | |||
|                         return typeof arguments_[number] != 'undefined' ? arguments_[number] : match; | ||||
|                     }); | ||||
|                 }; | ||||
|                 if (process.env.CLOUD_RUNNER_PRE_CACHE_PULL) { | ||||
|                     cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PULL)); | ||||
|                 if (cloud_runner_state_1.CloudRunnerState.buildParams.cachePullOverrideCommand) { | ||||
|                     cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(cloud_runner_state_1.CloudRunnerState.buildParams.cachePullOverrideCommand)); | ||||
|                 } | ||||
|                 if (fs_1.default.existsSync(`${cacheSelection}.zip`)) { | ||||
|                     const resultsFolder = `results${cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid}`; | ||||
|  | @ -2594,7 +2599,7 @@ const __1 = __nccwpck_require__(41359); | |||
| const yaml_1 = __importDefault(__nccwpck_require__(44603)); | ||||
| class CloudRunnerBuildCommandProcessor { | ||||
|     static ProcessCommands(commands, buildParameters) { | ||||
|         const hooks = CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`all`)); | ||||
|         const hooks = CloudRunnerBuildCommandProcessor.getHooks(buildParameters.customJobHooks).filter((x) => x.step.includes(`all`)); | ||||
|         return `echo "---"
 | ||||
|       echo "start cloud runner init" | ||||
|       ${__1.Input.cloudRunnerTests ? '' : '#'} printenv | ||||
|  | @ -2606,8 +2611,8 @@ class CloudRunnerBuildCommandProcessor { | |||
|       ---${buildParameters.logId}" | ||||
|     `;
 | ||||
|     } | ||||
|     static getHooks() { | ||||
|         const experimentHooks = process.env.EXPERIMENTAL_HOOKS; | ||||
|     static getHooks(customJobHooks) { | ||||
|         const experimentHooks = customJobHooks; | ||||
|         let output = new Array(); | ||||
|         if (experimentHooks && experimentHooks !== '') { | ||||
|             try { | ||||
|  | @ -2764,7 +2769,7 @@ class TaskParameterSerializer { | |||
|         let array = new Array(); | ||||
|         array = TaskParameterSerializer.readBuildParameters(array); | ||||
|         array = TaskParameterSerializer.readInput(array); | ||||
|         const configurableHooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks(); | ||||
|         const configurableHooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks(cloud_runner_state_1.CloudRunnerState.buildParams.customJobHooks); | ||||
|         const secrets = configurableHooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0); | ||||
|         if (secrets.length > 0) { | ||||
|             // eslint-disable-next-line unicorn/no-array-reduce
 | ||||
|  | @ -2867,10 +2872,10 @@ class CloudRunnerState { | |||
|         return path_1.default.join(CloudRunnerState.cacheFolderFull, `Library`); | ||||
|     } | ||||
|     static get unityBuilderRepoUrl() { | ||||
|         return `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`; | ||||
|         return `https://${CloudRunnerState.buildParams.gitPrivateToken}@github.com/game-ci/unity-builder.git`; | ||||
|     } | ||||
|     static get targetBuildRepoUrl() { | ||||
|         return `https://${CloudRunnerState.buildParams.githubToken}@github.com/${CloudRunnerState.buildParams.githubRepo}.git`; | ||||
|         return `https://${CloudRunnerState.buildParams.gitPrivateToken}@github.com/${CloudRunnerState.buildParams.githubRepo}.git`; | ||||
|     } | ||||
|     static get buildVolumeFolder() { | ||||
|         return 'data'; | ||||
|  | @ -2938,7 +2943,7 @@ class BuildStep { | |||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             cloud_runner_logger_1.default.logLine(` `); | ||||
|             cloud_runner_logger_1.default.logLine('Starting part 2/2 (build unity project)'); | ||||
|             const hooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`setup`)); | ||||
|             const hooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks(cloud_runner_state_1.CloudRunnerState.buildParams.customJobHooks).filter((x) => x.step.includes(`setup`)); | ||||
|             return yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid, image, `${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '} | ||||
|         export GITHUB_WORKSPACE="${cloud_runner_state_1.CloudRunnerState.repoPathFull}" | ||||
|         cp -r "${path_1.default | ||||
|  | @ -3021,7 +3026,7 @@ class SetupStep { | |||
|             try { | ||||
|                 cloud_runner_logger_1.default.log(` `); | ||||
|                 cloud_runner_logger_1.default.logLine('Starting step 1/2 (setup game files from repository)'); | ||||
|                 const hooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`setup`)); | ||||
|                 const hooks = cloud_runner_build_command_process_1.CloudRunnerBuildCommandProcessor.getHooks(cloud_runner_state_1.CloudRunnerState.buildParams.customJobHooks).filter((x) => x.step.includes(`setup`)); | ||||
|                 return yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid, image, `apk update -q
 | ||||
|         apk add git-lfs jq tree zip unzip nodejs -q | ||||
|         ${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '} | ||||
|  | @ -3656,6 +3661,35 @@ class ActionYamlReader { | |||
| exports.ActionYamlReader = ActionYamlReader; | ||||
| 
 | ||||
| 
 | ||||
| /***/ }), | ||||
| 
 | ||||
| /***/ 2263: | ||||
| /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { | ||||
| 
 | ||||
| "use strict"; | ||||
| 
 | ||||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||||
|     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||||
|     return new (P || (P = Promise))(function (resolve, reject) { | ||||
|         function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||||
|         function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||||
|         function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||||
|         step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||||
|     }); | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", ({ value: true })); | ||||
| exports.GenericInputReader = void 0; | ||||
| const cloud_runner_system_1 = __nccwpck_require__(66879); | ||||
| class GenericInputReader { | ||||
|     static Run(command) { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             return yield cloud_runner_system_1.CloudRunnerSystem.Run(command); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
| exports.GenericInputReader = GenericInputReader; | ||||
| 
 | ||||
| 
 | ||||
| /***/ }), | ||||
| 
 | ||||
| /***/ 24271: | ||||
|  | @ -3809,6 +3843,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | |||
| Object.defineProperty(exports, "__esModule", ({ value: true })); | ||||
| const fs_1 = __importDefault(__nccwpck_require__(57147)); | ||||
| const path_1 = __importDefault(__nccwpck_require__(71017)); | ||||
| const generic_input_reader_1 = __nccwpck_require__(2263); | ||||
| const git_repo_1 = __nccwpck_require__(24271); | ||||
| const github_cli_1 = __nccwpck_require__(44990); | ||||
| const platform_1 = __importDefault(__nccwpck_require__(9707)); | ||||
|  | @ -3823,18 +3858,60 @@ class Input { | |||
|     static get cloudRunnerTests() { | ||||
|         return Input.getInput(`cloudRunnerTests`) || Input.getInput(`CloudRunnerTests`) || false; | ||||
|     } | ||||
|     static shouldUseOverride(query) { | ||||
|         if (Input.readInputOverrideCommand() !== '') { | ||||
|             if (Input.readInputFromOverrideList() !== '') { | ||||
|                 return Input.readInputFromOverrideList().split(', ').includes(query) ? true : false; | ||||
|             } | ||||
|             else { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     static queryOverride(query) { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             if (!this.shouldUseOverride(query)) { | ||||
|                 throw new Error(`Should not be trying to run override query on ${query}`); | ||||
|             } | ||||
|             // eslint-disable-next-line func-style
 | ||||
|             const formatFunction = function (format) { | ||||
|                 const arguments_ = Array.prototype.slice.call([query], 1); | ||||
|                 return format.replace(/{(\d+)}/g, function (match, number) { | ||||
|                     return typeof arguments_[number] != 'undefined' ? arguments_[number] : match; | ||||
|                 }); | ||||
|             }; | ||||
|             return yield generic_input_reader_1.GenericInputReader.Run(formatFunction(Input.readInputOverrideCommand())); | ||||
|         }); | ||||
|     } | ||||
|     static PopulateQueryOverrideInput() { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             const queries = Input.readInputFromOverrideList().split(', '); | ||||
|             Input.queryOverrides = new Array(); | ||||
|             for (const element of queries) { | ||||
|                 if (Input.shouldUseOverride(element)) { | ||||
|                     Input.queryOverrides.Push(yield Input.queryOverride(element)); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|     static getInput(query) { | ||||
|         const coreInput = core.getInput(query); | ||||
|         if (Input.githubInputEnabled && coreInput && coreInput !== '') { | ||||
|             return coreInput; | ||||
|         } | ||||
|         return Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined | ||||
|             ? Input.cliOptions[query] | ||||
|             : process.env[query] !== undefined | ||||
|                 ? process.env[query] | ||||
|                 : process.env[Input.ToEnvVarFormat(query)] | ||||
|                     ? process.env[Input.ToEnvVarFormat(query)] | ||||
|                     : ''; | ||||
|         if (Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined) { | ||||
|             return Input.cliOptions[query]; | ||||
|         } | ||||
|         if (Input.queryOverrides !== undefined && Input.queryOverrides[query] !== undefined) { | ||||
|             return Input.queryOverrides[query]; | ||||
|         } | ||||
|         if (process.env[query] !== undefined) { | ||||
|             return process.env[query]; | ||||
|         } | ||||
|         if (process.env[Input.ToEnvVarFormat(query)] !== undefined) { | ||||
|             return process.env[Input.ToEnvVarFormat(query)]; | ||||
|         } | ||||
|         return ''; | ||||
|     } | ||||
|     static get region() { | ||||
|         return Input.getInput('region') || 'eu-west-2'; | ||||
|  | @ -3944,9 +4021,27 @@ class Input { | |||
|     } | ||||
|     static gitPrivateToken() { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             return core.getInput('gitPrivateToken') || (yield Input.githubToken()); | ||||
|             return core.getInput('gitPrivateToken') || (yield github_cli_1.GithubCliReader.GetGitHubAuthToken()) || ''; | ||||
|         }); | ||||
|     } | ||||
|     static get customJob() { | ||||
|         return Input.getInput('customJob') || ''; | ||||
|     } | ||||
|     static customJobHooks() { | ||||
|         return Input.getInput('customJobHooks') || ''; | ||||
|     } | ||||
|     static cachePushOverrideCommand() { | ||||
|         return Input.getInput('cachePushOverrideCommand') || ''; | ||||
|     } | ||||
|     static cachePullOverrideCommand() { | ||||
|         return Input.getInput('cachePullOverrideCommand') || ''; | ||||
|     } | ||||
|     static readInputFromOverrideList() { | ||||
|         return Input.getInput('readInputFromOverrideList') || ''; | ||||
|     } | ||||
|     static readInputOverrideCommand() { | ||||
|         return Input.getInput('readInputOverrideCommand') || ''; | ||||
|     } | ||||
|     static get chownFilesTo() { | ||||
|         return Input.getInput('chownFilesTo') || ''; | ||||
|     } | ||||
|  | @ -3960,9 +4055,6 @@ class Input { | |||
|     static get preBuildSteps() { | ||||
|         return Input.getInput('preBuildSteps') || ''; | ||||
|     } | ||||
|     static get customJob() { | ||||
|         return Input.getInput('customJob') || ''; | ||||
|     } | ||||
|     static get awsBaseStackName() { | ||||
|         return Input.getInput('awsBaseStackName') || 'game-ci'; | ||||
|     } | ||||
|  | @ -3975,11 +4067,6 @@ class Input { | |||
|     static get cloudRunnerMemory() { | ||||
|         return Input.getInput('cloudRunnerMemory') || '750M'; | ||||
|     } | ||||
|     static githubToken() { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             return Input.getInput('githubToken') || (yield github_cli_1.GithubCliReader.GetGitHubAuthToken()) || ''; | ||||
|         }); | ||||
|     } | ||||
|     static get kubeConfig() { | ||||
|         return Input.getInput('kubeConfig') || ''; | ||||
|     } | ||||
|  |  | |||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -36,12 +36,16 @@ class BuildParameters { | |||
|   public remoteBuildCluster!: string; | ||||
|   public awsStackName!: string; | ||||
|   public kubeConfig!: string; | ||||
|   public githubToken!: string; | ||||
|   public cloudRunnerMemory!: string; | ||||
|   public cloudRunnerCpu!: string; | ||||
|   public kubeVolumeSize!: string; | ||||
|   public kubeVolume!: string; | ||||
|   public chownFilesTo!: string; | ||||
|   public customJobHooks!: string; | ||||
|   public cachePushOverrideCommand!: string; | ||||
|   public cachePullOverrideCommand!: string; | ||||
|   public readInputFromOverrideList!: string; | ||||
|   public readInputOverrideCommand!: string; | ||||
| 
 | ||||
|   public postBuildSteps!: string; | ||||
|   public preBuildSteps!: string; | ||||
|  | @ -64,6 +68,8 @@ class BuildParameters { | |||
| 
 | ||||
|     const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion); | ||||
| 
 | ||||
|     await Input.PopulateQueryOverrideInput(); | ||||
| 
 | ||||
|     let unitySerial = ''; | ||||
|     if (!process.env.UNITY_SERIAL) { | ||||
|       //No serial was present so it is a personal license that we need to convert
 | ||||
|  | @ -107,7 +113,6 @@ class BuildParameters { | |||
|       cloudRunnerCluster: Input.cloudRunnerCluster, | ||||
|       awsBaseStackName: Input.awsBaseStackName, | ||||
|       kubeConfig: Input.kubeConfig, | ||||
|       githubToken: await Input.githubToken(), | ||||
|       cloudRunnerMemory: Input.cloudRunnerMemory, | ||||
|       cloudRunnerCpu: Input.cloudRunnerCpu, | ||||
|       kubeVolumeSize: Input.kubeVolumeSize, | ||||
|  | @ -123,6 +128,11 @@ class BuildParameters { | |||
|       gitSha: Input.gitSha, | ||||
|       logId: customAlphabet(CloudRunnerConstants.alphabet, 9)(), | ||||
|       buildGuid: CloudRunnerNamespace.generateBuildName(Input.runNumber, Input.targetPlatform), | ||||
|       customJobHooks: Input.customJobHooks(), | ||||
|       cachePullOverrideCommand: Input.cachePullOverrideCommand(), | ||||
|       cachePushOverrideCommand: Input.cachePushOverrideCommand(), | ||||
|       readInputOverrideCommand: Input.readInputOverrideCommand(), | ||||
|       readInputFromOverrideList: Input.readInputFromOverrideList(), | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -38,8 +38,8 @@ export class Caching { | |||
|       await CloudRunnerSystem.Run(`zip ${cacheKey}.zip ${path.basename(sourceFolder)}`); | ||||
|       assert(fs.existsSync(`${cacheKey}.zip`), 'cache zip exists'); | ||||
|       assert(fs.existsSync(path.basename(sourceFolder)), 'source folder exists'); | ||||
|       if (process.env.CLOUD_RUNNER_PRE_CACHE_PUSH) { | ||||
|         CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PUSH)); | ||||
|       if (CloudRunnerState.buildParams.cachePushOverrideCommand) { | ||||
|         CloudRunnerSystem.Run(formatFunction(CloudRunnerState.buildParams.cachePushOverrideCommand)); | ||||
|       } | ||||
|       CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`); | ||||
|       RemoteClientLogger.log(`moved ${cacheKey}.zip to ${cacheFolder}`); | ||||
|  | @ -86,8 +86,8 @@ export class Caching { | |||
|         }); | ||||
|       }; | ||||
| 
 | ||||
|       if (process.env.CLOUD_RUNNER_PRE_CACHE_PULL) { | ||||
|         CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PULL)); | ||||
|       if (CloudRunnerState.buildParams.cachePullOverrideCommand) { | ||||
|         CloudRunnerSystem.Run(formatFunction(CloudRunnerState.buildParams.cachePullOverrideCommand)); | ||||
|       } | ||||
| 
 | ||||
|       if (fs.existsSync(`${cacheSelection}.zip`)) { | ||||
|  |  | |||
|  | @ -4,7 +4,9 @@ import CloudRunnerSecret from './cloud-runner-secret'; | |||
| 
 | ||||
| export class CloudRunnerBuildCommandProcessor { | ||||
|   public static ProcessCommands(commands: string, buildParameters: BuildParameters): string { | ||||
|     const hooks = CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`all`)); | ||||
|     const hooks = CloudRunnerBuildCommandProcessor.getHooks(buildParameters.customJobHooks).filter((x) => | ||||
|       x.step.includes(`all`), | ||||
|     ); | ||||
| 
 | ||||
|     return `echo "---"
 | ||||
|       echo "start cloud runner init" | ||||
|  | @ -18,8 +20,8 @@ export class CloudRunnerBuildCommandProcessor { | |||
|     `;
 | ||||
|   } | ||||
| 
 | ||||
|   public static getHooks(): Hook[] { | ||||
|     const experimentHooks = process.env.EXPERIMENTAL_HOOKS; | ||||
|   public static getHooks(customJobHooks): Hook[] { | ||||
|     const experimentHooks = customJobHooks; | ||||
|     let output = new Array<Hook>(); | ||||
|     if (experimentHooks && experimentHooks !== '') { | ||||
|       try { | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ export class TaskParameterSerializer { | |||
|     let array = new Array(); | ||||
|     array = TaskParameterSerializer.readBuildParameters(array); | ||||
|     array = TaskParameterSerializer.readInput(array); | ||||
|     const configurableHooks = CloudRunnerBuildCommandProcessor.getHooks(); | ||||
|     const configurableHooks = CloudRunnerBuildCommandProcessor.getHooks(CloudRunnerState.buildParams.customJobHooks); | ||||
|     const secrets = configurableHooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0); | ||||
|     if (secrets.length > 0) { | ||||
|       // eslint-disable-next-line unicorn/no-array-reduce
 | ||||
|  |  | |||
|  | @ -64,11 +64,11 @@ export class CloudRunnerState { | |||
|   } | ||||
| 
 | ||||
|   public static get unityBuilderRepoUrl(): string { | ||||
|     return `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`; | ||||
|     return `https://${CloudRunnerState.buildParams.gitPrivateToken}@github.com/game-ci/unity-builder.git`; | ||||
|   } | ||||
| 
 | ||||
|   public static get targetBuildRepoUrl(): string { | ||||
|     return `https://${CloudRunnerState.buildParams.githubToken}@github.com/${CloudRunnerState.buildParams.githubRepo}.git`; | ||||
|     return `https://${CloudRunnerState.buildParams.gitPrivateToken}@github.com/${CloudRunnerState.buildParams.githubRepo}.git`; | ||||
|   } | ||||
| 
 | ||||
|   public static get buildVolumeFolder() { | ||||
|  |  | |||
|  | @ -24,7 +24,9 @@ export class BuildStep implements StepInterface { | |||
|   ) { | ||||
|     CloudRunnerLogger.logLine(` `); | ||||
|     CloudRunnerLogger.logLine('Starting part 2/2 (build unity project)'); | ||||
|     const hooks = CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`setup`)); | ||||
|     const hooks = CloudRunnerBuildCommandProcessor.getHooks(CloudRunnerState.buildParams.customJobHooks).filter((x) => | ||||
|       x.step.includes(`setup`), | ||||
|     ); | ||||
|     return await CloudRunnerState.CloudRunnerProviderPlatform.runTask( | ||||
|       CloudRunnerState.buildParams.buildGuid, | ||||
|       image, | ||||
|  |  | |||
|  | @ -35,7 +35,9 @@ export class SetupStep implements StepInterface { | |||
|     try { | ||||
|       CloudRunnerLogger.log(` `); | ||||
|       CloudRunnerLogger.logLine('Starting step 1/2 (setup game files from repository)'); | ||||
|       const hooks = CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`setup`)); | ||||
|       const hooks = CloudRunnerBuildCommandProcessor.getHooks(CloudRunnerState.buildParams.customJobHooks).filter((x) => | ||||
|         x.step.includes(`setup`), | ||||
|       ); | ||||
|       return await CloudRunnerState.CloudRunnerProviderPlatform.runTask( | ||||
|         CloudRunnerState.buildParams.buildGuid, | ||||
|         image, | ||||
|  |  | |||
|  | @ -0,0 +1,7 @@ | |||
| import { CloudRunnerSystem } from '../cli/remote-client/remote-client-services/cloud-runner-system'; | ||||
| 
 | ||||
| export class GenericInputReader { | ||||
|   public static async Run(command) { | ||||
|     return await CloudRunnerSystem.Run(command); | ||||
|   } | ||||
| } | ||||
|  | @ -1,5 +1,6 @@ | |||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import { GenericInputReader } from './input-readers/generic-input-reader'; | ||||
| import { GitRepoReader } from './input-readers/git-repo'; | ||||
| import { GithubCliReader } from './input-readers/github-cli'; | ||||
| import Platform from './platform'; | ||||
|  | @ -13,25 +14,70 @@ const core = require('@actions/core'); | |||
|  */ | ||||
| class Input { | ||||
|   public static cliOptions; | ||||
|   public static queryOverrides; | ||||
|   public static githubInputEnabled: boolean = true; | ||||
| 
 | ||||
|   // also enabled debug logging for cloud runner
 | ||||
|   static get cloudRunnerTests(): boolean { | ||||
|     return Input.getInput(`cloudRunnerTests`) || Input.getInput(`CloudRunnerTests`) || false; | ||||
|   } | ||||
|   private static shouldUseOverride(query) { | ||||
|     if (Input.readInputOverrideCommand() !== '') { | ||||
|       if (Input.readInputFromOverrideList() !== '') { | ||||
|         return Input.readInputFromOverrideList().split(', ').includes(query) ? true : false; | ||||
|       } else { | ||||
|         return true; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private static async queryOverride(query) { | ||||
|     if (!this.shouldUseOverride(query)) { | ||||
|       throw new Error(`Should not be trying to run override query on ${query}`); | ||||
|     } | ||||
|     // eslint-disable-next-line func-style
 | ||||
|     const formatFunction = function (format: string) { | ||||
|       const arguments_ = Array.prototype.slice.call([query], 1); | ||||
|       return format.replace(/{(\d+)}/g, function (match, number) { | ||||
|         return typeof arguments_[number] != 'undefined' ? arguments_[number] : match; | ||||
|       }); | ||||
|     }; | ||||
|     return await GenericInputReader.Run(formatFunction(Input.readInputOverrideCommand())); | ||||
|   } | ||||
| 
 | ||||
|   public static async PopulateQueryOverrideInput() { | ||||
|     const queries = Input.readInputFromOverrideList().split(', '); | ||||
|     Input.queryOverrides = new Array(); | ||||
|     for (const element of queries) { | ||||
|       if (Input.shouldUseOverride(element)) { | ||||
|         Input.queryOverrides.Push(await Input.queryOverride(element)); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private static getInput(query) { | ||||
|     const coreInput = core.getInput(query); | ||||
|     if (Input.githubInputEnabled && coreInput && coreInput !== '') { | ||||
|       return coreInput; | ||||
|     } | ||||
| 
 | ||||
|     return Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined | ||||
|       ? Input.cliOptions[query] | ||||
|       : process.env[query] !== undefined | ||||
|       ? process.env[query] | ||||
|       : process.env[Input.ToEnvVarFormat(query)] | ||||
|       ? process.env[Input.ToEnvVarFormat(query)] | ||||
|       : ''; | ||||
|     if (Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined) { | ||||
|       return Input.cliOptions[query]; | ||||
|     } | ||||
| 
 | ||||
|     if (Input.queryOverrides !== undefined && Input.queryOverrides[query] !== undefined) { | ||||
|       return Input.queryOverrides[query]; | ||||
|     } | ||||
| 
 | ||||
|     if (process.env[query] !== undefined) { | ||||
|       return process.env[query]; | ||||
|     } | ||||
| 
 | ||||
|     if (process.env[Input.ToEnvVarFormat(query)] !== undefined) { | ||||
|       return process.env[Input.ToEnvVarFormat(query)]; | ||||
|     } | ||||
| 
 | ||||
|     return ''; | ||||
|   } | ||||
|   static get region(): string { | ||||
|     return Input.getInput('region') || 'eu-west-2'; | ||||
|  | @ -155,7 +201,31 @@ class Input { | |||
|   } | ||||
| 
 | ||||
|   static async gitPrivateToken() { | ||||
|     return core.getInput('gitPrivateToken') || (await Input.githubToken()); | ||||
|     return core.getInput('gitPrivateToken') || (await GithubCliReader.GetGitHubAuthToken()) || ''; | ||||
|   } | ||||
| 
 | ||||
|   static get customJob() { | ||||
|     return Input.getInput('customJob') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static customJobHooks() { | ||||
|     return Input.getInput('customJobHooks') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static cachePushOverrideCommand() { | ||||
|     return Input.getInput('cachePushOverrideCommand') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static cachePullOverrideCommand() { | ||||
|     return Input.getInput('cachePullOverrideCommand') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static readInputFromOverrideList() { | ||||
|     return Input.getInput('readInputFromOverrideList') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static readInputOverrideCommand() { | ||||
|     return Input.getInput('readInputOverrideCommand') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static get chownFilesTo() { | ||||
|  | @ -176,10 +246,6 @@ class Input { | |||
|     return Input.getInput('preBuildSteps') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static get customJob() { | ||||
|     return Input.getInput('customJob') || ''; | ||||
|   } | ||||
| 
 | ||||
|   static get awsBaseStackName() { | ||||
|     return Input.getInput('awsBaseStackName') || 'game-ci'; | ||||
|   } | ||||
|  | @ -196,10 +262,6 @@ class Input { | |||
|     return Input.getInput('cloudRunnerMemory') || '750M'; | ||||
|   } | ||||
| 
 | ||||
|   static async githubToken() { | ||||
|     return Input.getInput('githubToken') || (await GithubCliReader.GetGitHubAuthToken()) || ''; | ||||
|   } | ||||
| 
 | ||||
|   static get kubeConfig() { | ||||
|     return Input.getInput('kubeConfig') || ''; | ||||
|   } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue