2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import fs from 'fs';
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 02:34:27 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import path from 'path';
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:35:09 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { RemoteClientSystem } from './remote-client-system';
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export class SetupRemoteRepository {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  static LFS_ASSETS_HASH;
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-19 01:45:55 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  public static async run() {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    try {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.mkdirSync(CloudRunnerState.buildPathFull);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.mkdirSync(CloudRunnerState.repoPathFull);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.cloneRepoWithoutLFSFiles();
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.createLFSHashFiles();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.printLFSHashState();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const lfsCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lfs`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const libraryCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lib`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:51:42 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`tree ${libraryCacheFolder}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`tree ${CloudRunnerState.builderPathFull}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-27 01:19:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.libraryCaching(libraryCacheFolder);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.lfsCaching(lfsCacheFolder);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.printCacheState(lfsCacheFolder, libraryCacheFolder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.pullLatestLFS();
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await SetupRemoteRepository.cacheLatestLFSFiles(lfsCacheFolder);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      SetupRemoteRepository.handleCachePurging();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } catch (error) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      throw error;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static async printLFSHashState() {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      `echo ' '
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-19 22:04:02 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo 'Contents of .lfs-assets-guid file:'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      cat .lfs-assets-guid
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo ' '
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo 'Contents of .lfs-assets-guid-sum file:'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      cat .lfs-assets-guid-sum
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo ' '
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-21 06:47:29 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo 'Source repository initialized'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      ls ${CloudRunnerState.projectPathFull}
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      echo ' '`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static async printCacheState(lfsCacheFolder: string, libraryCacheFolder: string) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      `echo ' '
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo "LFS cache for $branch"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      du -sch "${lfsCacheFolder}/"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo '**'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo "Library cache for $branch"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      du -sch "${libraryCacheFolder}/"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo '**'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo "Branch: $branch"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      du -sch "${CloudRunnerState.cacheFolderFull}/"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo '**'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      echo 'Full cache'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      du -sch "${CloudRunnerState.cacheFolderFull}/"
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      echo ' '`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static handleCachePurging() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (process.env.purgeRemoteCaching !== undefined) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`purging ${CloudRunnerState.purgeRemoteCaching}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.rmdirSync(CloudRunnerState.cacheFolder, { recursive: true });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  private static async cacheLatestLFSFiles(lfsCacheFolder: string) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process.chdir(`${CloudRunnerState.lfsDirectory}/..`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(`zip -r "${SetupRemoteRepository.LFS_ASSETS_HASH}.zip" "lfs"`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(fs.existsSync(`${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`).toString());
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:14:32 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      `cp "${SetupRemoteRepository.LFS_ASSETS_HASH}.zip" "${path.join(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lfsCacheFolder,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        `${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      )}"`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`copied ${SetupRemoteRepository.LFS_ASSETS_HASH} to ${lfsCacheFolder}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static async pullLatestLFS() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process.chdir(CloudRunnerState.repoPathFull);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(`git lfs pull`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`pulled latest LFS files`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  private static async lfsCaching(lfsCacheFolder: string) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(` `);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`LFS Caching`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-27 00:44:54 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!fs.existsSync(lfsCacheFolder)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.mkdirSync(lfsCacheFolder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process.chdir(lfsCacheFolder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let latestLFSCacheFile;
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (fs.existsSync(`${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`)) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`Match found: using large file hash match ${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      latestLFSCacheFile = `${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`;
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      latestLFSCacheFile = await RemoteClientSystem.Run(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (fs.existsSync(latestLFSCacheFile)) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`LFS cache exists`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.rmdirSync(CloudRunnerState.lfsDirectory, { recursive: true });
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:07:28 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        `LFS cache exists from build ${latestLFSCacheFile} from ${CloudRunnerState.buildParams.branch}`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        `unzip -q "${lfsCacheFolder}/${latestLFSCacheFile}" -d "${path.join(CloudRunnerState.repoPathFull, `.git`)}"`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`git LFS folder, (should not contain $latestLFSCacheFile)`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-27 01:19:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  private static async libraryCaching(libraryCacheFolder: string) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`Starting checks of cache for the Unity project Library and git LFS files`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 02:34:27 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!fs.existsSync(libraryCacheFolder)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.mkdirSync(libraryCacheFolder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`Library Caching`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //if the unity git project has included the library delete it and echo a warning
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (fs.existsSync(CloudRunnerState.libraryFolderFull)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.rmdirSync(CloudRunnerState.libraryFolderFull, { recursive: true });
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        `!Warning!: The Unity library was included in the git repository (this isn't usually a good practice)`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //Restore library cache
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:35:09 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const latestLibraryCacheFile = await RemoteClientSystem.Run(`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(`ls -lh "${libraryCacheFolder}"`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(`Checking if Library cache ${libraryCacheFolder}/${latestLibraryCacheFile} exists`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (fs.existsSync(latestLibraryCacheFile)) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`Library cache exists`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      const latestCacheFilePath = path.join(libraryCacheFolder, latestLibraryCacheFile);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`unzip -q "${latestCacheFilePath}" -d "$projectPathFull"`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 01:58:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-24 02:34:27 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static async createLFSHashFiles() {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 20:34:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    await RemoteClientSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 18:10:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    SetupRemoteRepository.LFS_ASSETS_HASH = fs.readFileSync(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      `${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      'utf8',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    CloudRunnerLogger.logCli(SetupRemoteRepository.LFS_ASSETS_HASH);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-25 19:47:22 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  private static async cloneRepoWithoutLFSFiles() {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    try {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`Initializing source repository for cloning with caching of LFS files`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      process.chdir(CloudRunnerState.repoPathFull);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`git config --global advice.detachedHead false`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`Cloning the repository being built:`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`git lfs install --skip-smudge`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(CloudRunnerState.targetBuildRepoUrl);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 02:06:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`git clone ${CloudRunnerState.targetBuildRepoUrl} ${CloudRunnerState.repoPathFull}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:47:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`ls -lh`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`tree`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`${CloudRunnerState.buildParams.branch}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 00:53:07 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      await RemoteClientSystem.Run(`git checkout ${CloudRunnerState.buildParams.branch}`);
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-26 19:24:10 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      CloudRunnerLogger.logCli(`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
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |