| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  | import fs from 'fs'; | 
					
						
							|  |  |  | import path from 'path'; | 
					
						
							| 
									
										
										
										
											2022-03-07 15:17:13 +00:00
										 |  |  | import { GenericInputReader } from './input-readers/generic-input-reader'; | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  | import { GitRepoReader } from './input-readers/git-repo'; | 
					
						
							|  |  |  | import { GithubCliReader } from './input-readers/github-cli'; | 
					
						
							| 
									
										
										
										
											2020-01-20 23:06:14 +00:00
										 |  |  | import Platform from './platform'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-22 14:05:15 +00:00
										 |  |  | const core = require('@actions/core'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Input variables specified in workflows using "with" prop. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that input is always passed as a string, even booleans. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-01-20 23:06:14 +00:00
										 |  |  | class Input { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   public static cliOptions; | 
					
						
							| 
									
										
										
										
											2022-03-07 15:17:13 +00:00
										 |  |  |   public static queryOverrides; | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   public static githubInputEnabled: boolean = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // also enabled debug logging for cloud runner
 | 
					
						
							|  |  |  |   static get cloudRunnerTests(): boolean { | 
					
						
							|  |  |  |     return Input.getInput(`cloudRunnerTests`) || Input.getInput(`CloudRunnerTests`) || false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-03-07 15:17:13 +00:00
										 |  |  |   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)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   private static getInput(query) { | 
					
						
							|  |  |  |     const coreInput = core.getInput(query); | 
					
						
							|  |  |  |     if (Input.githubInputEnabled && coreInput && coreInput !== '') { | 
					
						
							|  |  |  |       return coreInput; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 15:17:13 +00:00
										 |  |  |     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 ''; | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   static get region(): string { | 
					
						
							|  |  |  |     return Input.getInput('region') || 'eu-west-2'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-03-13 23:32:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   static async githubRepo() { | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |       Input.getInput('GITHUB_REPOSITORY') || | 
					
						
							|  |  |  |       Input.getInput('GITHUB_REPO') || | 
					
						
							|  |  |  |       (await GitRepoReader.GetRemote()) || | 
					
						
							|  |  |  |       'game-ci/unity-builder' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   static async branch() { | 
					
						
							|  |  |  |     if (await GitRepoReader.GetBranch()) { | 
					
						
							|  |  |  |       return await GitRepoReader.GetBranch(); | 
					
						
							|  |  |  |     } else if (Input.getInput(`GITHUB_REF`)) { | 
					
						
							|  |  |  |       return Input.getInput(`GITHUB_REF`).replace('refs/', '').replace(`head/`, ''); | 
					
						
							|  |  |  |     } else if (Input.getInput('branch')) { | 
					
						
							|  |  |  |       return Input.getInput('branch'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return 'main'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get gitSha() { | 
					
						
							|  |  |  |     if (Input.getInput(`GITHUB_SHA`)) { | 
					
						
							|  |  |  |       return Input.getInput(`GITHUB_SHA`); | 
					
						
							|  |  |  |     } else if (Input.getInput(`GitSHA`)) { | 
					
						
							|  |  |  |       return Input.getInput(`GitSHA`); | 
					
						
							|  |  |  |     } else if (GitRepoReader.GetSha()) { | 
					
						
							|  |  |  |       return GitRepoReader.GetSha(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   static get runNumber() { | 
					
						
							|  |  |  |     return Input.getInput('GITHUB_RUN_NUMBER') || '0'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get targetPlatform() { | 
					
						
							|  |  |  |     return Input.getInput('targetPlatform') || Platform.default; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   static get unityVersion() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('unityVersion') || 'auto'; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 16:41:31 +00:00
										 |  |  |   static get customImage() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('customImage'); | 
					
						
							| 
									
										
										
										
											2020-09-18 16:41:31 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   static get projectPath() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     const input = Input.getInput('projectPath'); | 
					
						
							|  |  |  |     const rawProjectPath = input | 
					
						
							|  |  |  |       ? input | 
					
						
							|  |  |  |       : fs.existsSync(path.join('test-project', 'ProjectSettings', 'ProjectVersion.txt')) && | 
					
						
							|  |  |  |         !fs.existsSync(path.join('ProjectSettings', 'ProjectVersion.txt')) | 
					
						
							|  |  |  |       ? 'test-project' | 
					
						
							|  |  |  |       : '.'; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |     return rawProjectPath.replace(/\/$/, ''); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get buildName() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('buildName') || this.targetPlatform; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get buildsPath() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('buildsPath') || 'build'; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get buildMethod() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('buildMethod') || ''; // processed in docker file
 | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get customParameters() { | 
					
						
							|  |  |  |     return Input.getInput('customParameters') || ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   static get versioningStrategy() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('versioning') || 'Semantic'; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get specifiedVersion() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('version') || ''; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:44:56 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 22:02:05 +00:00
										 |  |  |   static get androidVersionCode() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidVersionCode'); | 
					
						
							| 
									
										
										
										
											2020-06-24 22:02:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   static get androidAppBundle() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     const input = Input.getInput('androidAppBundle') || false; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 14:30:06 +00:00
										 |  |  |     return input === 'true'; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get androidKeystoreName() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidKeystoreName') || ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get androidKeystoreBase64() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidKeystoreBase64') || ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get androidKeystorePass() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidKeystorePass') || ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get androidKeyaliasName() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidKeyaliasName') || ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get androidKeyaliasPass() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('androidKeyaliasPass') || ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 12:51:52 +00:00
										 |  |  |   static get androidTargetSdkVersion() { | 
					
						
							|  |  |  |     return core.getInput('androidTargetSdkVersion') || ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 21:51:10 +00:00
										 |  |  |   static get sshAgent() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('sshAgent') || ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static async gitPrivateToken() { | 
					
						
							| 
									
										
										
										
											2022-03-07 15:17:13 +00:00
										 |  |  |     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') || ''; | 
					
						
							| 
									
										
										
										
											2021-11-14 22:52:35 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-01 23:23:15 +00:00
										 |  |  |   static get chownFilesTo() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('chownFilesTo') || ''; | 
					
						
							| 
									
										
										
										
											2021-05-01 23:23:15 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get allowDirtyBuild() { | 
					
						
							|  |  |  |     const input = Input.getInput('allowDirtyBuild') || false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return input === 'true'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   static get postBuildSteps() { | 
					
						
							|  |  |  |     return Input.getInput('postBuildSteps') || ''; | 
					
						
							| 
									
										
										
										
											2021-04-20 20:46:37 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   static get preBuildSteps() { | 
					
						
							|  |  |  |     return Input.getInput('preBuildSteps') || ''; | 
					
						
							| 
									
										
										
										
											2021-04-20 20:46:37 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   static get awsBaseStackName() { | 
					
						
							|  |  |  |     return Input.getInput('awsBaseStackName') || 'game-ci'; | 
					
						
							| 
									
										
										
										
											2020-08-09 19:27:47 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get cloudRunnerCluster() { | 
					
						
							|  |  |  |     return Input.getInput('cloudRunnerCluster') || 'local'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get cloudRunnerCpu() { | 
					
						
							|  |  |  |     return Input.getInput('cloudRunnerCpu') || '1.0'; | 
					
						
							| 
									
										
										
										
											2020-08-09 19:27:47 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   static get cloudRunnerMemory() { | 
					
						
							|  |  |  |     return Input.getInput('cloudRunnerMemory') || '750M'; | 
					
						
							| 
									
										
										
										
											2020-08-09 19:27:47 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get kubeConfig() { | 
					
						
							|  |  |  |     return Input.getInput('kubeConfig') || ''; | 
					
						
							| 
									
										
										
										
											2020-08-09 19:27:47 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static get kubeVolume() { | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |     return Input.getInput('kubeVolume') || ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 19:19:28 +00:00
										 |  |  |   static get kubeVolumeSize() { | 
					
						
							|  |  |  |     return Input.getInput('kubeVolumeSize') || '5Gi'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-13 23:32:37 +00:00
										 |  |  |   static get kubeStorageClass(): string { | 
					
						
							|  |  |  |     return Input.getInput('kubeStorageClass') || ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 02:31:20 +00:00
										 |  |  |   public static ToEnvVarFormat(input: string) { | 
					
						
							|  |  |  |     return input | 
					
						
							|  |  |  |       .replace(/([A-Z])/g, ' $1') | 
					
						
							|  |  |  |       .trim() | 
					
						
							|  |  |  |       .toUpperCase() | 
					
						
							|  |  |  |       .replace(/ /g, '_'); | 
					
						
							| 
									
										
										
										
											2020-08-09 19:27:47 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-12-22 14:05:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-01-20 23:06:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default Input; |