unity-builder/src/model/cli/remote-client/setup-cloud-runner-reposito...

92 lines
3.7 KiB
TypeScript
Raw Normal View History

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-29 20:08:04 +00:00
import path from 'path';
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-31 02:08:16 +00:00
export class SetupCloudRunnerRepository {
2021-12-26 18:10:23 +00:00
static LFS_ASSETS_HASH;
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 02:08:16 +00:00
SetupCloudRunnerRepository.LFS_ASSETS_HASH = await LFSHashing.createLFSHashFiles();
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
2021-12-31 20:12:47 +00:00
RemoteClientLogger.log(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
2021-12-31 17:52:01 +00:00
}
2021-12-27 21:25:46 +00:00
await LFSHashing.printLFSHashState();
2021-12-31 20:12:47 +00:00
RemoteClientLogger.log(`Library Caching`);
if (!fs.existsSync(CloudRunnerState.libraryFolderFull)) {
RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
}
RemoteClientLogger.log(`LFS Caching`);
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.lfsDirectory, '..')}`);
}
2021-12-27 21:49:57 +00:00
await Caching.PullFromCache(
2021-12-27 22:39:02 +00:00
CloudRunnerState.lfsCacheFolder,
2021-12-27 21:49:57 +00:00
CloudRunnerState.lfsDirectory,
2021-12-31 02:08:16 +00:00
`${SetupCloudRunnerRepository.LFS_ASSETS_HASH}.zip`,
2021-12-27 21:49:57 +00:00
);
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.lfsDirectory, '..')}`);
}
2021-12-27 22:39:02 +00:00
await Caching.printCacheState(CloudRunnerState.lfsCacheFolder, CloudRunnerState.libraryCacheFolder);
2021-12-31 02:08:16 +00:00
await SetupCloudRunnerRepository.pullLatestLFS();
2021-12-27 21:53:22 +00:00
await Caching.PushToCache(
2021-12-27 22:39:02 +00:00
CloudRunnerState.lfsCacheFolder,
2021-12-27 21:53:22 +00:00
CloudRunnerState.lfsDirectory,
2021-12-31 02:08:16 +00:00
SetupCloudRunnerRepository.LFS_ASSETS_HASH,
2021-12-27 21:53:22 +00:00
);
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.libraryCacheFolder, '..')}`);
}
2021-12-28 12:57:27 +00:00
await Caching.PullFromCache(CloudRunnerState.libraryCacheFolder, CloudRunnerState.libraryFolderFull);
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.libraryCacheFolder, '..')}`);
}
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;
}
}
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-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
}
}