| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  | import { Input } from '../..'; | 
					
						
							|  |  |  | import ImageEnvironmentFactory from '../../image-environment-factory'; | 
					
						
							| 
									
										
										
										
											2021-12-29 23:42:06 +00:00
										 |  |  | import CloudRunnerEnvironmentVariable from './cloud-runner-environment-variable'; | 
					
						
							|  |  |  | import { CloudRunnerState } from '../state/cloud-runner-state'; | 
					
						
							| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class TaskParameterSerializer { | 
					
						
							|  |  |  |   public static readBuildEnvironmentVariables(): CloudRunnerEnvironmentVariable[] { | 
					
						
							|  |  |  |     return [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ContainerMemory', | 
					
						
							|  |  |  |         value: CloudRunnerState.buildParams.cloudRunnerMemory, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'ContainerCpu', | 
					
						
							|  |  |  |         value: CloudRunnerState.buildParams.cloudRunnerCpu, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'GITHUB_WORKSPACE', | 
					
						
							|  |  |  |         value: `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.buildGuid}/${CloudRunnerState.repositoryFolder}/`, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'BUILD_TARGET', | 
					
						
							|  |  |  |         value: CloudRunnerState.buildParams.platform, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       ...TaskParameterSerializer.serializeBuildParamsAndInput, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   private static get serializeBuildParamsAndInput() { | 
					
						
							| 
									
										
										
										
											2021-12-29 18:25:09 +00:00
										 |  |  |     let array = new Array(); | 
					
						
							|  |  |  |     array = TaskParameterSerializer.readBuildParameters(array); | 
					
						
							| 
									
										
										
										
											2021-12-29 23:42:06 +00:00
										 |  |  |     array = TaskParameterSerializer.readInput(array); | 
					
						
							| 
									
										
										
										
											2021-12-30 01:00:52 +00:00
										 |  |  |     array = array.filter((x) => x.value !== undefined && x.name !== '0'); | 
					
						
							| 
									
										
										
										
											2021-12-29 18:25:09 +00:00
										 |  |  |     return array; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static readBuildParameters(array: any[]) { | 
					
						
							| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  |     const keys = Object.keys(CloudRunnerState.buildParams); | 
					
						
							|  |  |  |     for (const element of keys) { | 
					
						
							| 
									
										
										
										
											2021-12-30 05:10:23 +00:00
										 |  |  |       array.push( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           name: element, | 
					
						
							|  |  |  |           value: `${CloudRunnerState.buildParams[element]}`, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           name: element | 
					
						
							|  |  |  |             .replace(/([A-Z])/g, ' $1') | 
					
						
							|  |  |  |             .trim() | 
					
						
							|  |  |  |             .toUpperCase() | 
					
						
							|  |  |  |             .replace(/ /g, '_'), | 
					
						
							|  |  |  |           value: `${CloudRunnerState.buildParams[element]}`, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-29 23:49:47 +00:00
										 |  |  |     array.push( | 
					
						
							|  |  |  |       { name: 'buildParameters', value: JSON.stringify(CloudRunnerState.buildParams) }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: Object.keys(CloudRunnerState.buildGuid)[0], | 
					
						
							|  |  |  |         value: CloudRunnerState.buildGuid, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-12-29 18:25:09 +00:00
										 |  |  |     return array; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static readInput(array: any[]) { | 
					
						
							| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  |     const input = Object.getOwnPropertyNames(Input); | 
					
						
							|  |  |  |     for (const element of input) { | 
					
						
							| 
									
										
										
										
											2021-12-29 18:25:09 +00:00
										 |  |  |       if (typeof Input[element] !== 'function') { | 
					
						
							| 
									
										
										
										
											2021-12-30 05:10:23 +00:00
										 |  |  |         array.push( | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             name: element, | 
					
						
							|  |  |  |             value: `${Input[element]}`, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             name: element | 
					
						
							|  |  |  |               .replace(/([A-Z])/g, ' $1') | 
					
						
							|  |  |  |               .trim() | 
					
						
							|  |  |  |               .toUpperCase() | 
					
						
							|  |  |  |               .replace(/ /g, '_'), | 
					
						
							|  |  |  |             value: `${Input[element]}`, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-12-23 18:36:30 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-12-23 18:10:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     return array; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public static setupDefaultSecrets() { | 
					
						
							|  |  |  |     CloudRunnerState.defaultSecrets = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'GithubToken', | 
					
						
							|  |  |  |         EnvironmentVariable: 'GITHUB_TOKEN', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.buildParams.githubToken, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'branch', | 
					
						
							|  |  |  |         EnvironmentVariable: 'branch', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.branchName, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'buildPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'buildPathFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.buildPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'projectPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'projectPathFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.projectPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'libraryFolderFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'libraryFolderFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.libraryFolderFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'builderPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'builderPathFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.builderPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'repoPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'repoPathFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.repoPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ParameterKey: 'steamPathFull', | 
					
						
							|  |  |  |         EnvironmentVariable: 'steamPathFull', | 
					
						
							|  |  |  |         ParameterValue: CloudRunnerState.steamPathFull, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |     CloudRunnerState.defaultSecrets.push( | 
					
						
							|  |  |  |       ...ImageEnvironmentFactory.getEnvironmentVariables(CloudRunnerState.buildParams).map((x) => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           ParameterKey: x.name, | 
					
						
							|  |  |  |           EnvironmentVariable: x.name, | 
					
						
							|  |  |  |           ParameterValue: x.value, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |