| 
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 |  |  | import fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2021-12-25 19:35:09 +00:00
										 |  |  | import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state'; | 
					
						
							| 
									
										
										
										
											2021-12-27 21:12:46 +00:00
										 |  |  | import { Caching } from './caching'; | 
					
						
							| 
									
										
										
										
											2021-12-27 21:25:46 +00:00
										 |  |  | import { LFSHashing } from './lfs-hashing'; | 
					
						
							| 
									
										
										
										
											2021-12-27 22:16:09 +00:00
										 |  |  | import { CloudRunnerAgentSystem } from './cloud-runner-agent-system'; | 
					
						
							| 
									
										
										
										
											2021-12-31 17:52:01 +00:00
										 |  |  | import { Input } from '../..'; | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  | import { RemoteClientLogger } from './remote-client-logger'; | 
					
						
							| 
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-31 02:08:16 +00:00
										 |  |  | export class SetupCloudRunnerRepository { | 
					
						
							| 
									
										
										
										
											2021-12-19 01:45:55 +00:00
										 |  |  |   public static async run() { | 
					
						
							| 
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2021-12-30 03:50:30 +00:00
										 |  |  |       await CloudRunnerAgentSystem.Run(`mkdir -p ${CloudRunnerState.buildPathFull}`); | 
					
						
							|  |  |  |       await CloudRunnerAgentSystem.Run(`mkdir -p ${CloudRunnerState.repoPathFull}`); | 
					
						
							| 
									
										
										
										
											2021-12-31 02:08:16 +00:00
										 |  |  |       await SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles(); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:33:55 +00:00
										 |  |  |       const lfsHashes = await LFSHashing.createLFSHashFiles(); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |       if (!fs.existsSync(CloudRunnerState.libraryFolderFull)) { | 
					
						
							|  |  |  |         RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-12-27 21:49:57 +00:00
										 |  |  |       await Caching.PullFromCache( | 
					
						
							| 
									
										
										
										
											2021-12-31 20:33:55 +00:00
										 |  |  |         CloudRunnerState.lfsCacheFolderFull, | 
					
						
							| 
									
										
										
										
											2021-12-27 21:49:57 +00:00
										 |  |  |         CloudRunnerState.lfsDirectory, | 
					
						
							| 
									
										
										
										
											2021-12-31 20:33:55 +00:00
										 |  |  |         `${lfsHashes.lfsGuid}.zip`, | 
					
						
							| 
									
										
										
										
											2021-12-27 21:49:57 +00:00
										 |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-12-31 02:08:16 +00:00
										 |  |  |       await SetupCloudRunnerRepository.pullLatestLFS(); | 
					
						
							| 
									
										
										
										
											2022-01-02 03:16:26 +00:00
										 |  |  |       await Caching.PushToCache( | 
					
						
							|  |  |  |         CloudRunnerState.lfsCacheFolderFull, | 
					
						
							|  |  |  |         CloudRunnerState.lfsDirectory, | 
					
						
							|  |  |  |         `${lfsHashes.lfsGuid}.zip`, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:33:55 +00:00
										 |  |  |       await Caching.PullFromCache(CloudRunnerState.libraryCacheFolderFull, CloudRunnerState.libraryFolderFull); | 
					
						
							| 
									
										
										
										
											2021-12-29 20:08:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-27 21:25:46 +00:00
										 |  |  |       Caching.handleCachePurging(); | 
					
						
							| 
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 |  |  |     } catch (error) { | 
					
						
							|  |  |  |       throw error; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static async cloneRepoWithoutLFSFiles() { | 
					
						
							| 
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |       RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`); | 
					
						
							| 
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 |  |  |       process.chdir(CloudRunnerState.repoPathFull); | 
					
						
							| 
									
										
										
										
											2021-12-27 21:53:22 +00:00
										 |  |  |       await CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |       RemoteClientLogger.log(`Cloning the repository being built:`); | 
					
						
							| 
									
										
										
										
											2021-12-27 21:53:22 +00:00
										 |  |  |       await CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`); | 
					
						
							|  |  |  |       await CloudRunnerAgentSystem.Run( | 
					
						
							|  |  |  |         `git clone ${CloudRunnerState.targetBuildRepoUrl} ${CloudRunnerState.repoPathFull}`, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-12-31 17:52:01 +00:00
										 |  |  |       if (Input.cloudRunnerTests) { | 
					
						
							|  |  |  |         await CloudRunnerAgentSystem.Run(`ls -lh`); | 
					
						
							|  |  |  |         await CloudRunnerAgentSystem.Run(`tree`); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |       RemoteClientLogger.log(`${CloudRunnerState.buildParams.branch}`); | 
					
						
							| 
									
										
										
										
											2021-12-27 21:53:22 +00:00
										 |  |  |       await CloudRunnerAgentSystem.Run(`git checkout ${CloudRunnerState.buildParams.branch}`); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |       RemoteClientLogger.log(`Checked out ${process.env.GITHUB_SHA}`); | 
					
						
							| 
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 |  |  |     } catch (error) { | 
					
						
							|  |  |  |       throw error; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-19 01:45:55 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-12-27 21:49:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private static async pullLatestLFS() { | 
					
						
							|  |  |  |     process.chdir(CloudRunnerState.repoPathFull); | 
					
						
							| 
									
										
										
										
											2021-12-27 21:53:22 +00:00
										 |  |  |     await CloudRunnerAgentSystem.Run(`git lfs pull`); | 
					
						
							| 
									
										
										
										
											2021-12-31 20:12:47 +00:00
										 |  |  |     RemoteClientLogger.log(`pulled latest LFS files`); | 
					
						
							| 
									
										
										
										
											2021-12-27 21:49:57 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-12-19 01:45:55 +00:00
										 |  |  | } |