2022-02-01 02:31:20 +00:00
|
|
|
import fs from 'fs';
|
2022-04-03 00:31:08 +00:00
|
|
|
import CloudRunner from '../../cloud-runner/cloud-runner';
|
|
|
|
|
import { CloudRunnerFolders } from '../../cloud-runner/services/cloud-runner-folders';
|
2022-02-01 02:31:20 +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';
|
|
|
|
|
import { RemoteClientLogger } from './remote-client-services/remote-client-logger';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { assert } from 'console';
|
|
|
|
|
|
|
|
|
|
export class SetupCloudRunnerRepository {
|
|
|
|
|
public static async run() {
|
|
|
|
|
try {
|
2022-04-03 00:31:08 +00:00
|
|
|
await CloudRunnerSystem.Run(`mkdir -p ${CloudRunnerFolders.buildPathFull}`);
|
|
|
|
|
await CloudRunnerSystem.Run(`mkdir -p ${CloudRunnerFolders.repoPathFull}`);
|
|
|
|
|
await CloudRunnerSystem.Run(`mkdir -p ${CloudRunnerFolders.cacheFolderFull}`);
|
2022-02-01 02:31:20 +00:00
|
|
|
|
2022-04-03 00:31:08 +00:00
|
|
|
process.chdir(CloudRunnerFolders.repoPathFull);
|
2022-02-01 02:31:20 +00:00
|
|
|
await SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles();
|
|
|
|
|
const lfsHashes = await LFSHashing.createLFSHashFiles();
|
2022-04-03 00:31:08 +00:00
|
|
|
if (fs.existsSync(CloudRunnerFolders.libraryFolderFull)) {
|
2022-02-01 02:31:20 +00:00
|
|
|
RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
|
|
|
|
|
}
|
|
|
|
|
await Caching.PullFromCache(
|
2022-04-03 00:31:08 +00:00
|
|
|
CloudRunnerFolders.lfsCacheFolderFull,
|
|
|
|
|
CloudRunnerFolders.lfsDirectoryFull,
|
2022-03-06 01:45:27 +00:00
|
|
|
`${lfsHashes.lfsGuidSum}`,
|
2022-02-01 02:31:20 +00:00
|
|
|
);
|
|
|
|
|
await SetupCloudRunnerRepository.pullLatestLFS();
|
|
|
|
|
await Caching.PushToCache(
|
2022-04-03 00:31:08 +00:00
|
|
|
CloudRunnerFolders.lfsCacheFolderFull,
|
|
|
|
|
CloudRunnerFolders.lfsDirectoryFull,
|
2022-03-06 01:45:27 +00:00
|
|
|
`${lfsHashes.lfsGuidSum}`,
|
2022-02-01 02:31:20 +00:00
|
|
|
);
|
2022-04-03 00:31:08 +00:00
|
|
|
await Caching.PullFromCache(CloudRunnerFolders.libraryCacheFolderFull, CloudRunnerFolders.libraryFolderFull);
|
2022-02-01 02:31:20 +00:00
|
|
|
Caching.handleCachePurging();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async cloneRepoWithoutLFSFiles() {
|
|
|
|
|
try {
|
2022-04-03 00:31:08 +00:00
|
|
|
process.chdir(`${CloudRunnerFolders.repoPathFull}`);
|
2022-02-01 02:31:20 +00:00
|
|
|
RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
|
|
|
|
|
await CloudRunnerSystem.Run(`git config --global advice.detachedHead false`);
|
|
|
|
|
RemoteClientLogger.log(`Cloning the repository being built:`);
|
2022-03-15 00:00:52 +00:00
|
|
|
await CloudRunnerSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"`);
|
|
|
|
|
await CloudRunnerSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process --skip"`);
|
|
|
|
|
await CloudRunnerSystem.Run(`git lfs install`);
|
2022-02-01 02:31:20 +00:00
|
|
|
await CloudRunnerSystem.Run(
|
2022-04-03 00:31:08 +00:00
|
|
|
`git clone ${CloudRunnerFolders.targetBuildRepoUrl} ${path.resolve(
|
2022-02-01 02:31:20 +00:00
|
|
|
`..`,
|
2022-04-03 00:31:08 +00:00
|
|
|
path.basename(CloudRunnerFolders.repoPathFull),
|
2022-02-01 02:31:20 +00:00
|
|
|
)}`,
|
|
|
|
|
);
|
|
|
|
|
assert(fs.existsSync(`.git`));
|
2022-04-03 00:31:08 +00:00
|
|
|
RemoteClientLogger.log(`${CloudRunner.buildParameters.branch}`);
|
|
|
|
|
await CloudRunnerSystem.Run(`git checkout ${CloudRunner.buildParameters.branch}`);
|
2022-02-01 02:31:20 +00:00
|
|
|
assert(fs.existsSync(path.join(`.git`, `lfs`)), 'LFS folder should not exist before caching');
|
|
|
|
|
RemoteClientLogger.log(`Checked out ${process.env.GITHUB_SHA}`);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async pullLatestLFS() {
|
2022-04-03 00:31:08 +00:00
|
|
|
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) {
|
|
|
|
|
await CloudRunnerSystem.Run(`ls -lh ${CloudRunnerFolders.lfsDirectoryFull}/..`);
|
2022-03-05 19:08:38 +00:00
|
|
|
}
|
2022-04-03 00:31:08 +00:00
|
|
|
process.chdir(CloudRunnerFolders.repoPathFull);
|
2022-03-15 00:00:52 +00:00
|
|
|
await CloudRunnerSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge -- %f"`);
|
|
|
|
|
await CloudRunnerSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process"`);
|
2022-02-01 02:31:20 +00:00
|
|
|
await CloudRunnerSystem.Run(`git lfs pull`);
|
|
|
|
|
RemoteClientLogger.log(`pulled latest LFS files`);
|
2022-04-03 00:31:08 +00:00
|
|
|
assert(fs.existsSync(CloudRunnerFolders.lfsDirectoryFull));
|
2022-03-05 19:08:38 +00:00
|
|
|
|
2022-04-03 00:31:08 +00:00
|
|
|
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) {
|
|
|
|
|
await CloudRunnerSystem.Run(`ls -lh ${CloudRunnerFolders.lfsDirectoryFull}/..`);
|
2022-03-05 19:08:38 +00:00
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
|
|
|
|
}
|