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

72 lines
3.0 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';
2022-01-02 22:48:43 +00:00
import { Caching } from './remote-client-services/caching';
import { LFSHashing } from './remote-client-services/lfs-hashing';
import { CloudRunnerSystem } from './remote-client-services/cloud-runner-system';
2021-12-31 17:52:01 +00:00
import { Input } from '../..';
2022-01-02 22:48:43 +00:00
import { RemoteClientLogger } from './remote-client-services/remote-client-logger';
import path from 'path';
2022-01-02 23:44:49 +00:00
import { assert } from 'console';
2021-12-31 02:08:16 +00:00
export class SetupCloudRunnerRepository {
public static async run() {
2021-12-26 00:47:33 +00:00
try {
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.Run(`mkdir -p ${CloudRunnerState.buildPathFull}`);
await CloudRunnerSystem.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();
2022-01-02 22:34:10 +00:00
if (fs.existsSync(CloudRunnerState.libraryFolderFull)) {
2021-12-31 20:12:47 +00:00
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,
2022-01-03 02:38:37 +00:00
CloudRunnerState.lfsDirectoryFull,
2022-01-02 07:16:24 +00:00
`${lfsHashes.lfsGuid}`,
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,
2022-01-03 02:38:37 +00:00
CloudRunnerState.lfsDirectoryFull,
2022-01-02 07:16:24 +00:00
`${lfsHashes.lfsGuid}`,
2022-01-02 03:16:26 +00:00
);
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;
}
}
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`);
2022-01-02 22:48:43 +00:00
process.chdir(`${path.join(CloudRunnerState.repoPathFull, '..')}`);
await CloudRunnerSystem.Run(`git config --global advice.detachedHead false`);
2021-12-31 20:12:47 +00:00
RemoteClientLogger.log(`Cloning the repository being built:`);
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.Run(`git lfs install --skip-smudge`);
await CloudRunnerSystem.Run(
`git clone ${CloudRunnerState.targetBuildRepoUrl} ${path.basename(CloudRunnerState.repoPathFull)}`,
);
process.chdir(`${CloudRunnerState.repoPathFull}`);
2022-01-02 23:44:49 +00:00
assert(fs.existsSync(`.git`));
2021-12-31 17:52:01 +00:00
if (Input.cloudRunnerTests) {
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.Run(`ls -lh`);
await CloudRunnerSystem.Run(`tree`);
2021-12-31 17:52:01 +00:00
}
2021-12-31 20:12:47 +00:00
RemoteClientLogger.log(`${CloudRunnerState.buildParams.branch}`);
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.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);
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.Run(`git lfs pull`);
2021-12-31 20:12:47 +00:00
RemoteClientLogger.log(`pulled latest LFS files`);
2022-01-03 02:38:37 +00:00
assert(fs.existsSync(CloudRunnerState.lfsDirectoryFull));
2022-01-03 03:16:26 +00:00
await CloudRunnerSystem.Run(`ls -lh ${CloudRunnerState.lfsDirectoryFull}/..`);
2021-12-27 21:49:57 +00:00
}
}