pull/310/head
Frostebite 2021-12-31 02:08:16 +00:00
parent 902e3b3ea7
commit b74e55e108
6 changed files with 145 additions and 307 deletions

217
dist/index.js vendored
View File

@ -390,26 +390,29 @@ class CLI {
static RunCli(options) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Entrypoint: ${options.mode}`);
if (options.mode === 'remote-cli') {
yield remote_client_1.RemoteClient.Run();
}
else {
options.versioning = 'None';
__1.Input.cliOptions = options;
const buildParameter = yield __1.BuildParameters.create();
const baseImage = new __1.ImageTag(buildParameter);
yield __1.CloudRunner.run(buildParameter, baseImage.toString());
const container = new Array();
container.push({
key: `remote-cli`,
asyncFunc: remote_client_1.RemoteClient.Run,
}, {
key: `cli`,
asyncFunc: () => __awaiter(this, void 0, void 0, function* () {
options.versioning = 'None';
__1.Input.cliOptions = options;
const buildParameter = yield __1.BuildParameters.create();
const baseImage = new __1.ImageTag(buildParameter);
return yield __1.CloudRunner.run(buildParameter, baseImage.toString());
}),
});
const results = container.filter((x) => x.key === options.mode);
if (results.length === 0) {
throw new Error('no CLI mode found');
}
return yield results[0].asyncFunc();
});
}
static isCliMode(options) {
switch (options.mode) {
case 'cli':
case 'remote-cli':
return true;
default:
return false;
}
return options.mode !== undefined && options.mode === '';
}
static SetupCli() {
__1.Input.githubEnabled = false;
@ -598,95 +601,6 @@ class CloudRunnerAgentSystem {
exports.CloudRunnerAgentSystem = CloudRunnerAgentSystem;
/***/ }),
/***/ 21811:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerRepositorySetup = void 0;
const console_1 = __webpack_require__(57082);
const fs_1 = __importDefault(__webpack_require__(35747));
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const caching_1 = __webpack_require__(35010);
const lfs_hashing_1 = __webpack_require__(47011);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const path_1 = __importDefault(__webpack_require__(85622));
class CloudRunnerRepositorySetup {
static run() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cloud_runner_state_1.CloudRunnerState.buildPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield CloudRunnerRepositorySetup.cloneRepoWithoutLFSFiles();
CloudRunnerRepositorySetup.LFS_ASSETS_HASH = yield lfs_hashing_1.LFSHashing.createLFSHashFiles();
cloud_runner_logger_1.default.logCli(CloudRunnerRepositorySetup.LFS_ASSETS_HASH);
yield lfs_hashing_1.LFSHashing.printLFSHashState();
cloud_runner_logger_1.default.logCli(`Library Caching`);
console_1.assert(!fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull), `!Warning!: The Unity library was included in the git repository`);
cloud_runner_logger_1.default.logCli(`LFS Caching`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.lfsDirectory, '..')}`);
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, `${CloudRunnerRepositorySetup.LFS_ASSETS_HASH}.zip`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.lfsDirectory, '..')}`);
yield caching_1.Caching.printCacheState(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.libraryCacheFolder);
yield CloudRunnerRepositorySetup.pullLatestLFS();
yield caching_1.Caching.PushToCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, CloudRunnerRepositorySetup.LFS_ASSETS_HASH);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, '..')}`);
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, cloud_runner_state_1.CloudRunnerState.libraryFolderFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, '..')}`);
caching_1.Caching.handleCachePurging();
}
catch (error) {
throw error;
}
});
}
static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.logCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logCli(`Cloning the repository being built:`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git clone ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree`);
cloud_runner_logger_1.default.logCli(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
cloud_runner_logger_1.default.logCli(`Checked out ${process.env.GITHUB_SHA}`);
}
catch (error) {
throw error;
}
});
}
static pullLatestLFS() {
return __awaiter(this, void 0, void 0, function* () {
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs pull`);
cloud_runner_logger_1.default.logCli(`pulled latest LFS files`);
});
}
}
exports.CloudRunnerRepositorySetup = CloudRunnerRepositorySetup;
/***/ }),
/***/ 95575:
@ -706,13 +620,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClient = void 0;
const cloud_runner_state_1 = __webpack_require__(70912);
const cloud_runner_repository_setup_1 = __webpack_require__(21811);
const setup_cloud_runner_repository_1 = __webpack_require__(39656);
class RemoteClient {
static Run() {
return __awaiter(this, void 0, void 0, function* () {
const buildParameter = JSON.parse(process.env.buildParameters || '{}');
cloud_runner_state_1.CloudRunnerState.setup(buildParameter);
yield cloud_runner_repository_setup_1.CloudRunnerRepositorySetup.run();
yield setup_cloud_runner_repository_1.SetupCloudRunnerRepository.run();
});
}
}
@ -775,6 +689,95 @@ class LFSHashing {
exports.LFSHashing = LFSHashing;
/***/ }),
/***/ 39656:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.SetupCloudRunnerRepository = void 0;
const console_1 = __webpack_require__(57082);
const fs_1 = __importDefault(__webpack_require__(35747));
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const caching_1 = __webpack_require__(35010);
const lfs_hashing_1 = __webpack_require__(47011);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const path_1 = __importDefault(__webpack_require__(85622));
class SetupCloudRunnerRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cloud_runner_state_1.CloudRunnerState.buildPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles();
SetupCloudRunnerRepository.LFS_ASSETS_HASH = yield lfs_hashing_1.LFSHashing.createLFSHashFiles();
cloud_runner_logger_1.default.logCli(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
yield lfs_hashing_1.LFSHashing.printLFSHashState();
cloud_runner_logger_1.default.logCli(`Library Caching`);
console_1.assert(!fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull), `!Warning!: The Unity library was included in the git repository`);
cloud_runner_logger_1.default.logCli(`LFS Caching`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.lfsDirectory, '..')}`);
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, `${SetupCloudRunnerRepository.LFS_ASSETS_HASH}.zip`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.lfsDirectory, '..')}`);
yield caching_1.Caching.printCacheState(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.libraryCacheFolder);
yield SetupCloudRunnerRepository.pullLatestLFS();
yield caching_1.Caching.PushToCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, SetupCloudRunnerRepository.LFS_ASSETS_HASH);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, '..')}`);
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, cloud_runner_state_1.CloudRunnerState.libraryFolderFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.libraryCacheFolder, '..')}`);
caching_1.Caching.handleCachePurging();
}
catch (error) {
throw error;
}
});
}
static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.logCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logCli(`Cloning the repository being built:`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git clone ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree`);
cloud_runner_logger_1.default.logCli(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
cloud_runner_logger_1.default.logCli(`Checked out ${process.env.GITHUB_SHA}`);
}
catch (error) {
throw error;
}
});
}
static pullLatestLFS() {
return __awaiter(this, void 0, void 0, function* () {
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs pull`);
cloud_runner_logger_1.default.logCli(`pulled latest LFS files`);
});
}
}
exports.SetupCloudRunnerRepository = SetupCloudRunnerRepository;
/***/ }),
/***/ 28730:

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -7,25 +7,35 @@ export class CLI {
static async RunCli(options: any): Promise<void> {
core.info(`Entrypoint: ${options.mode}`);
if (options.mode === 'remote-cli') {
await RemoteClient.Run();
} else {
options.versioning = 'None';
Input.cliOptions = options;
const buildParameter = await BuildParameters.create();
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
const container = new Array();
container.push(
{
key: `remote-cli`,
asyncFunc: RemoteClient.Run,
},
{
key: `cli`,
asyncFunc: async () => {
options.versioning = 'None';
Input.cliOptions = options;
const buildParameter = await BuildParameters.create();
const baseImage = new ImageTag(buildParameter);
return await CloudRunner.run(buildParameter, baseImage.toString());
},
},
);
const results = container.filter((x) => x.key === options.mode);
if (results.length === 0) {
throw new Error('no CLI mode found');
}
return await results[0].asyncFunc();
}
static isCliMode(options: any) {
switch (options.mode) {
case 'cli':
case 'remote-cli':
return true;
default:
return false;
}
return options.mode !== undefined && options.mode === '';
}
public static SetupCli() {
Input.githubEnabled = false;
const program = new Command();

View File

@ -1,10 +1,10 @@
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerRepositorySetup } from './cloud-runner-repository-setup';
import { SetupCloudRunnerRepository } from './setup-cloud-runner-repository';
export class RemoteClient {
static async Run() {
const buildParameter = JSON.parse(process.env.buildParameters || '{}');
CloudRunnerState.setup(buildParameter);
await CloudRunnerRepositorySetup.run();
await SetupCloudRunnerRepository.run();
}
}

View File

@ -7,16 +7,16 @@ import { LFSHashing } from './lfs-hashing';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
import path from 'path';
export class CloudRunnerRepositorySetup {
export class SetupCloudRunnerRepository {
static LFS_ASSETS_HASH;
public static async run() {
try {
await CloudRunnerAgentSystem.Run(`mkdir -p ${CloudRunnerState.buildPathFull}`);
await CloudRunnerAgentSystem.Run(`mkdir -p ${CloudRunnerState.repoPathFull}`);
await CloudRunnerRepositorySetup.cloneRepoWithoutLFSFiles();
await SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles();
CloudRunnerRepositorySetup.LFS_ASSETS_HASH = await LFSHashing.createLFSHashFiles();
CloudRunnerLogger.logCli(CloudRunnerRepositorySetup.LFS_ASSETS_HASH);
SetupCloudRunnerRepository.LFS_ASSETS_HASH = await LFSHashing.createLFSHashFiles();
CloudRunnerLogger.logCli(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
await LFSHashing.printLFSHashState();
CloudRunnerLogger.logCli(`Library Caching`);
assert(
@ -28,15 +28,15 @@ export class CloudRunnerRepositorySetup {
await Caching.PullFromCache(
CloudRunnerState.lfsCacheFolder,
CloudRunnerState.lfsDirectory,
`${CloudRunnerRepositorySetup.LFS_ASSETS_HASH}.zip`,
`${SetupCloudRunnerRepository.LFS_ASSETS_HASH}.zip`,
);
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.lfsDirectory, '..')}`);
await Caching.printCacheState(CloudRunnerState.lfsCacheFolder, CloudRunnerState.libraryCacheFolder);
await CloudRunnerRepositorySetup.pullLatestLFS();
await SetupCloudRunnerRepository.pullLatestLFS();
await Caching.PushToCache(
CloudRunnerState.lfsCacheFolder,
CloudRunnerState.lfsDirectory,
CloudRunnerRepositorySetup.LFS_ASSETS_HASH,
SetupCloudRunnerRepository.LFS_ASSETS_HASH,
);
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.libraryCacheFolder, '..')}`);
await Caching.PullFromCache(CloudRunnerState.libraryCacheFolder, CloudRunnerState.libraryFolderFull);

View File

@ -1,175 +0,0 @@
import fs from 'fs';
import path from 'path';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
export class SetupRemoteRepository {
static LFS_ASSETS_HASH;
public static async run() {
try {
fs.mkdirSync(CloudRunnerState.buildPathFull);
fs.mkdirSync(CloudRunnerState.repoPathFull);
await SetupRemoteRepository.cloneRepoWithoutLFSFiles();
await SetupRemoteRepository.createLFSHashFiles();
await SetupRemoteRepository.printLFSHashState();
const lfsCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lfs`);
const libraryCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lib`);
await CloudRunnerAgentSystem.Run(`tree ${libraryCacheFolder}`);
await CloudRunnerAgentSystem.Run(`tree ${CloudRunnerState.builderPathFull}`);
await SetupRemoteRepository.libraryCaching(lfsCacheFolder, libraryCacheFolder);
await SetupRemoteRepository.lfsCaching(lfsCacheFolder);
await SetupRemoteRepository.printCacheState(lfsCacheFolder, libraryCacheFolder);
await SetupRemoteRepository.pullLatestLFS();
await SetupRemoteRepository.cacheLatestLFSFiles(lfsCacheFolder);
SetupRemoteRepository.handleCachePurging();
} catch (error) {
throw error;
}
}
private static async printLFSHashState() {
await CloudRunnerAgentSystem.Run(
`echo ' '
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 ' '
echo 'Source repository initialized'
ls ${CloudRunnerState.projectPathFull}
echo ' '`,
);
}
private static async printCacheState(lfsCacheFolder: string, libraryCacheFolder: string) {
await CloudRunnerAgentSystem.Run(
`echo ' '
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}/"
echo ' '`,
);
}
private static handleCachePurging() {
if (process.env.purgeRemoteCaching !== undefined) {
CloudRunnerLogger.logCli(`purging ${CloudRunnerState.purgeRemoteCaching}`);
fs.rmdirSync(CloudRunnerState.cacheFolder, { recursive: true });
}
}
private static async cacheLatestLFSFiles(lfsCacheFolder: string) {
process.chdir(`${CloudRunnerState.lfsDirectory}/..`);
await CloudRunnerAgentSystem.Run(`zip -r "${SetupRemoteRepository.LFS_ASSETS_HASH}.zip" "lfs"`);
CloudRunnerLogger.logCli(fs.existsSync(`${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`).toString());
await CloudRunnerAgentSystem.Run(
`cp "${SetupRemoteRepository.LFS_ASSETS_HASH}.zip" "${path.join(
lfsCacheFolder,
`${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`,
)}"`,
);
CloudRunnerLogger.logCli(`copied ${SetupRemoteRepository.LFS_ASSETS_HASH} to ${lfsCacheFolder}`);
}
private static async pullLatestLFS() {
process.chdir(CloudRunnerState.repoPathFull);
await CloudRunnerAgentSystem.Run(`git lfs pull`);
CloudRunnerLogger.logCli(`pulled latest LFS files`);
}
private static async lfsCaching(lfsCacheFolder: string) {
CloudRunnerLogger.logCli(` `);
CloudRunnerLogger.logCli(`LFS Caching`);
if (!fs.existsSync(lfsCacheFolder)) {
fs.mkdirSync(lfsCacheFolder);
}
process.chdir(lfsCacheFolder);
let latestLFSCacheFile;
if (fs.existsSync(`${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`)) {
CloudRunnerLogger.logCli(`Match found: using large file hash match ${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`);
latestLFSCacheFile = `${SetupRemoteRepository.LFS_ASSETS_HASH}.zip`;
} else {
latestLFSCacheFile = await CloudRunnerAgentSystem.Run(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
}
if (fs.existsSync(latestLFSCacheFile)) {
CloudRunnerLogger.logCli(`LFS cache exists`);
fs.rmdirSync(CloudRunnerState.lfsDirectory, { recursive: true });
CloudRunnerLogger.logCli(
`LFS cache exists from build ${latestLFSCacheFile} from ${CloudRunnerState.buildParams.branch}`,
);
await CloudRunnerAgentSystem.Run(
`unzip -q "${lfsCacheFolder}/${latestLFSCacheFile}" -d "${path.join(CloudRunnerState.repoPathFull, `.git`)}"`,
);
CloudRunnerLogger.logCli(`git LFS folder, (should not contain $latestLFSCacheFile)`);
}
}
private static async libraryCaching(lfsCacheFolder: string, libraryCacheFolder: string) {
CloudRunnerLogger.logCli(`Starting checks of cache for the Unity project Library and git LFS files`);
if (!fs.existsSync(libraryCacheFolder)) {
fs.mkdirSync(libraryCacheFolder);
}
CloudRunnerLogger.logCli(`Library Caching`);
//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 });
CloudRunnerLogger.logCli(
`!Warning!: The Unity library was included in the git repository (this isn't usually a good practice)`,
);
}
//Restore library cache
const latestLibraryCacheFile = await CloudRunnerAgentSystem.Run(
`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`,
);
await CloudRunnerAgentSystem.Run(`ls -lh "${libraryCacheFolder}"`);
CloudRunnerLogger.logCli(`Checking if Library cache ${libraryCacheFolder}/${latestLibraryCacheFile} exists`);
if (fs.existsSync(latestLibraryCacheFile)) {
CloudRunnerLogger.logCli(`Library cache exists`);
const latestCacheFilePath = path.join(libraryCacheFolder, latestLibraryCacheFile);
await CloudRunnerAgentSystem.Run(`unzip -q "${latestCacheFilePath}" -d "$projectPathFull"`);
}
}
private static async createLFSHashFiles() {
await CloudRunnerAgentSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
await CloudRunnerAgentSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
SetupRemoteRepository.LFS_ASSETS_HASH = fs.readFileSync(
`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`,
'utf8',
);
CloudRunnerLogger.logCli(SetupRemoteRepository.LFS_ASSETS_HASH);
}
private static async cloneRepoWithoutLFSFiles() {
try {
CloudRunnerLogger.logCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(CloudRunnerState.repoPathFull);
await CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
CloudRunnerLogger.logCli(`Cloning the repository being built:`);
await CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
CloudRunnerLogger.logCli(CloudRunnerState.targetBuildRepoUrl);
await CloudRunnerAgentSystem.Run(
`git clone ${CloudRunnerState.targetBuildRepoUrl} ${CloudRunnerState.repoPathFull}`,
);
await CloudRunnerAgentSystem.Run(`ls -lh`);
await CloudRunnerAgentSystem.Run(`tree`);
CloudRunnerLogger.logCli(`${CloudRunnerState.buildParams.branch}`);
await CloudRunnerAgentSystem.Run(`git checkout ${CloudRunnerState.buildParams.branch}`);
CloudRunnerLogger.logCli(`Checked out ${process.env.GITHUB_SHA}`);
} catch (error) {
throw error;
}
}
}