pull/310/head
Frostebite 2021-12-31 22:34:35 +00:00
parent 3e25417543
commit debf49c0a5
5 changed files with 404 additions and 29 deletions

395
dist/index.js vendored
View File

@ -370,7 +370,12 @@ function GetCliFunctions(key) {
}
exports.GetCliFunctions = GetCliFunctions;
function GetAllCliModes() {
return targets.map((x) => x.key);
return targets.map((x) => {
return {
key: x.key,
description: x.description,
};
});
}
exports.GetAllCliModes = GetAllCliModes;
@ -427,6 +432,9 @@ const core = __importStar(__webpack_require__(42186));
const action_yaml_1 = __webpack_require__(11091);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cli_decorator_1 = __webpack_require__(8731);
const remote_client_logger_1 = __webpack_require__(68972);
const cloud_runner_state_1 = __webpack_require__(70912);
const setup_cloud_runner_repository_1 = __webpack_require__(39656);
class CLI {
static RunCli(options) {
return __awaiter(this, void 0, void 0, function* () {
@ -471,13 +479,378 @@ class CLI {
return yield __1.CloudRunner.run(buildParameter, baseImage.toString());
});
}
static runRemoteClientJob() {
return __awaiter(this, void 0, void 0, function* () {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
remote_client_logger_1.RemoteClientLogger.log(`Build Params:
${JSON.stringify(buildParameter, undefined, 4)}
`);
cloud_runner_state_1.CloudRunnerState.setup(buildParameter);
yield setup_cloud_runner_repository_1.SetupCloudRunnerRepository.run();
});
}
}
__decorate([
cli_decorator_1.CliFunction(`cli`, `runs a cloud runner build`)
], CLI, "CLIBuild", null);
__decorate([
cli_decorator_1.CliFunction(`remote-cli`, `sets up a repository, usually before a game-ci build`)
], CLI, "runRemoteClientJob", null);
exports.CLI = CLI;
/***/ }),
/***/ 35010:
/***/ (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.Caching = void 0;
const console_1 = __webpack_require__(57082);
const fs_1 = __importDefault(__webpack_require__(35747));
const path_1 = __importDefault(__webpack_require__(85622));
const __1 = __webpack_require__(41359);
const cloud_runner_state_1 = __webpack_require__(70912);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const remote_client_logger_1 = __webpack_require__(68972);
class Caching {
static PushToCache(cacheFolder, sourceFolder, cacheKey) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (__1.Input.cloudRunnerTests) {
yield Caching.printFullCacheHierarchySize();
}
process.chdir(`${sourceFolder}/..`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${sourceFolder}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cacheFolder}`);
}
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`zip -r "${cacheKey}.zip" "${path_1.default.dirname(sourceFolder)}"`);
console_1.assert(fs_1.default.existsSync(`${cacheKey}.zip`));
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`cp "${cacheKey}.zip" "${path_1.default.join(cacheFolder, `${cacheKey}.zip`)}"`);
remote_client_logger_1.RemoteClientLogger.log(`copied ${cacheKey} to ${cacheFolder}`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cacheFolder}`);
}
if (__1.Input.cloudRunnerTests) {
yield Caching.printFullCacheHierarchySize();
}
}
catch (error) {
throw error;
}
});
}
static PullFromCache(cacheFolder, destinationFolder, cacheKey = ``) {
return __awaiter(this, void 0, void 0, function* () {
remote_client_logger_1.RemoteClientLogger.log(`Caching for ${path_1.default.dirname(destinationFolder)}`);
try {
if (!fs_1.default.existsSync(cacheFolder)) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cacheFolder}`);
}
if (!fs_1.default.existsSync(destinationFolder)) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${destinationFolder}`);
}
const latest = yield (yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -t "${cacheFolder}" | grep .zip$ | head -1`)).replace(/\n/g, ``);
process.chdir(cacheFolder);
let cacheSelection;
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cacheFolder}`);
}
if (cacheKey !== ``) {
cacheSelection = fs_1.default.existsSync(cacheKey) ? cacheKey : latest;
}
else {
cacheSelection = latest;
}
if (fs_1.default.existsSync(cacheSelection)) {
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
}
remote_client_logger_1.RemoteClientLogger.log(`cache item exists`);
console_1.assert(fs_1.default.existsSync(destinationFolder));
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`unzip "${cacheSelection}" -d "${destinationFolder}/.."`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
}
}
else {
remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`);
if (cacheSelection !== ``) {
throw new Error(`Failed to get cache item, but cache hit was found: ${cacheSelection}`);
}
}
}
catch (error) {
throw error;
}
});
}
static handleCachePurging() {
if (process.env.purgeRemoteCaching !== undefined) {
remote_client_logger_1.RemoteClientLogger.log(`purging ${cloud_runner_state_1.CloudRunnerState.purgeRemoteCaching}`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.cacheFolder, { recursive: true });
}
}
static printFullCacheHierarchySize() {
return __awaiter(this, void 0, void 0, function* () {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`echo ' '
echo "LFS cache for $branch"
du -sch "${cloud_runner_state_1.CloudRunnerState.lfsCacheFolderFull}/"
echo '**'
echo "Library cache for $branch"
du -sch "${cloud_runner_state_1.CloudRunnerState.libraryCacheFolderFull}/"
echo '**'
echo "Branch: $branch"
du -sch "${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}/"
echo '**'
echo 'Full cache'
du -sch "${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}/.."
echo ' '`);
});
}
}
exports.Caching = Caching;
/***/ }),
/***/ 87685:
/***/ (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());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerAgentSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const remote_client_logger_1 = __webpack_require__(68972);
class CloudRunnerAgentSystem {
static Run(command) {
return __awaiter(this, void 0, void 0, function* () {
remote_client_logger_1.RemoteClientLogger.log(`${command}`);
return yield new Promise((promise) => {
let output = '';
const child = child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
remote_client_logger_1.RemoteClientLogger.logCliError(`${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
remote_client_logger_1.RemoteClientLogger.logCliDiagnostic(`${stderr.toString()}`);
return;
}
const outputChunk = `${stdout}`;
output += outputChunk;
});
child.on('close', function (code) {
remote_client_logger_1.RemoteClientLogger.log(`[Exit code ${code}]`);
if (code !== 0) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
for (const element of outputLines) {
remote_client_logger_1.RemoteClientLogger.log(element);
}
promise(output);
});
});
});
}
}
exports.CloudRunnerAgentSystem = CloudRunnerAgentSystem;
/***/ }),
/***/ 47011:
/***/ (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.LFSHashing = void 0;
const path_1 = __importDefault(__webpack_require__(85622));
const cloud_runner_state_1 = __webpack_require__(70912);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const fs_1 = __importDefault(__webpack_require__(35747));
const console_1 = __webpack_require__(57082);
const __1 = __webpack_require__(41359);
const remote_client_logger_1 = __webpack_require__(68972);
class LFSHashing {
static createLFSHashFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
console_1.assert(fs_1.default.existsSync(`.lfs-assets-guid-sum`));
console_1.assert(fs_1.default.existsSync(`.lfs-assets-guid`));
const lfsHashes = {
lfsGuid: fs_1.default.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8'),
lfsGuidSum: fs_1.default.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid-sum`)}`, 'utf8'),
};
if (__1.Input.cloudRunnerTests) {
remote_client_logger_1.RemoteClientLogger.log(lfsHashes.lfsGuid);
remote_client_logger_1.RemoteClientLogger.log(lfsHashes.lfsGuidSum);
}
return lfsHashes;
}
catch (error) {
throw error;
}
});
}
}
exports.LFSHashing = LFSHashing;
/***/ }),
/***/ 68972:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClientLogger = void 0;
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class RemoteClientLogger {
static log(message) {
cloud_runner_logger_1.default.log(`[Client] ${message}`);
}
static logCliError(message) {
cloud_runner_logger_1.default.log(`[Client][Error] ${message}`);
}
static logCliDiagnostic(message) {
cloud_runner_logger_1.default.log(`[Client][Diagnostic] ${message}`);
}
static logWarning(message) {
cloud_runner_logger_1.default.logWarning(message);
}
}
exports.RemoteClientLogger = RemoteClientLogger;
/***/ }),
/***/ 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 fs_1 = __importDefault(__webpack_require__(35747));
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 __1 = __webpack_require__(41359);
const remote_client_logger_1 = __webpack_require__(68972);
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();
const lfsHashes = yield lfs_hashing_1.LFSHashing.createLFSHashFiles();
if (!fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull)) {
remote_client_logger_1.RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
}
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolderFull, cloud_runner_state_1.CloudRunnerState.lfsDirectory, `${lfsHashes.lfsGuid}.zip`);
yield SetupCloudRunnerRepository.pullLatestLFS();
yield caching_1.Caching.PushToCache(cloud_runner_state_1.CloudRunnerState.lfsCacheFolderFull, cloud_runner_state_1.CloudRunnerState.lfsDirectory, lfsHashes.lfsGuid);
yield caching_1.Caching.PullFromCache(cloud_runner_state_1.CloudRunnerState.libraryCacheFolderFull, cloud_runner_state_1.CloudRunnerState.libraryFolderFull);
caching_1.Caching.handleCachePurging();
}
catch (error) {
throw error;
}
});
}
static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
remote_client_logger_1.RemoteClientLogger.log(`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`);
remote_client_logger_1.RemoteClientLogger.log(`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}`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree`);
}
remote_client_logger_1.RemoteClientLogger.log(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
remote_client_logger_1.RemoteClientLogger.log(`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`);
remote_client_logger_1.RemoteClientLogger.log(`pulled latest LFS files`);
});
}
}
exports.SetupCloudRunnerRepository = SetupCloudRunnerRepository;
/***/ }),
/***/ 28730:
@ -2502,16 +2875,16 @@ class SetupStep {
try {
cloud_runner_logger_1.default.log(` `);
cloud_runner_logger_1.default.logLine('Starting step 1/2 (setup game files from repository)');
return yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid, image, `
apk update -q
apk add unzip zip git-lfs jq tree nodejs -q
${__1.Input.cloudRunnerTests ? '' : '#'} apk add tree -q
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
mkdir -p ${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}
git clone -b ${cloud_runner_state_1.CloudRunnerState.branchName} ${cloud_runner_state_1.CloudRunnerState.unityBuilderRepoUrl} "${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}"
${__1.Input.cloudRunnerTests ? '' : '#'} tree ${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}
chmod +x ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.builderPathFull, 'dist', `index.js`).replace(/\\/g, `/`)}
node ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.builderPathFull, 'dist', `index.js`).replace(/\\/g, `/`)} -m remote-cli
return yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid, image, `
apk update -q
apk add unzip zip git-lfs jq tree nodejs -q
${__1.Input.cloudRunnerTests ? '' : '#'} apk add tree -q
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
mkdir -p ${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}
git clone -b ${cloud_runner_state_1.CloudRunnerState.branchName} ${cloud_runner_state_1.CloudRunnerState.unityBuilderRepoUrl} "${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}"
${__1.Input.cloudRunnerTests ? '' : '#'} tree ${cloud_runner_state_1.CloudRunnerState.builderPathFull.replace(/\\/g, `/`)}
chmod +x ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.builderPathFull, 'dist', `index.js`).replace(/\\/g, `/`)}
node ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.builderPathFull, 'dist', `index.js`).replace(/\\/g, `/`)} -m remote-cli
`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}/`, environmentVariables, secrets);
}
catch (error) {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -14,5 +14,10 @@ export function GetCliFunctions(key) {
return targets.find((x) => x.key === key);
}
export function GetAllCliModes() {
return targets.map((x) => x.key);
return targets.map((x) => {
return {
key: x.key,
description: x.description,
};
});
}

View File

@ -4,6 +4,9 @@ import * as core from '@actions/core';
import { ActionYamlReader } from '../input-readers/action-yaml';
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger';
import { CliFunction, GetAllCliModes, GetCliFunctions } from './cli-decorator';
import { RemoteClientLogger } from './remote-client/remote-client-logger';
import { CloudRunnerState } from '../cloud-runner/state/cloud-runner-state';
import { SetupCloudRunnerRepository } from './remote-client/setup-cloud-runner-repository';
export class CLI {
static async RunCli(options: any): Promise<void> {
Input.githubInputEnabled = false;
@ -55,4 +58,14 @@ export class CLI {
const baseImage = new ImageTag(buildParameter);
return await CloudRunner.run(buildParameter, baseImage.toString());
}
@CliFunction(`remote-cli`, `sets up a repository, usually before a game-ci build`)
static async runRemoteClientJob() {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
RemoteClientLogger.log(`Build Params:
${JSON.stringify(buildParameter, undefined, 4)}
`);
CloudRunnerState.setup(buildParameter);
await SetupCloudRunnerRepository.run();
}
}

View File

@ -1,16 +0,0 @@
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CliFunction } from '../cli-decorator';
import { RemoteClientLogger } from './remote-client-logger';
import { SetupCloudRunnerRepository } from './setup-cloud-runner-repository';
export class RemoteClient {
@CliFunction(`remote-cli`, `sets up a repository, usually before a game-ci build`)
static async run() {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
RemoteClientLogger.log(`Build Params:
${JSON.stringify(buildParameter, undefined, 4)}
`);
CloudRunnerState.setup(buildParameter);
await SetupCloudRunnerRepository.run();
}
}