import cli files explicitly

pull/353/head
Frostebite 2022-04-07 20:29:26 +01:00
parent c214adb2d0
commit 26796c5dd5
9 changed files with 546 additions and 77 deletions

504
dist/index.js vendored
View File

@ -236,7 +236,7 @@ const cloud_runner_guid_1 = __importDefault(__nccwpck_require__(17963));
const input_1 = __importDefault(__nccwpck_require__(91933)); const input_1 = __importDefault(__nccwpck_require__(91933));
const platform_1 = __importDefault(__nccwpck_require__(9707)); const platform_1 = __importDefault(__nccwpck_require__(9707));
const unity_versioning_1 = __importDefault(__nccwpck_require__(17146)); const unity_versioning_1 = __importDefault(__nccwpck_require__(17146));
const versioning_1 = __importDefault(__nccwpck_require__(88729)); const versioning_1 = __importDefault(__nccwpck_require__(93901));
const git_repo_1 = __nccwpck_require__(24271); const git_repo_1 = __nccwpck_require__(24271);
const github_cli_1 = __nccwpck_require__(44990); const github_cli_1 = __nccwpck_require__(44990);
const cli_1 = __nccwpck_require__(55651); const cli_1 = __nccwpck_require__(55651);
@ -404,43 +404,49 @@ exports["default"] = Cache;
/***/ }), /***/ }),
/***/ 8731: /***/ 85301:
/***/ ((__unused_webpack_module, exports) => { /***/ ((__unused_webpack_module, exports) => {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GetAllCliModes = exports.GetCliFunctions = exports.CliFunction = void 0; exports.CliFunction = exports.CLIFunctionsRepository = void 0;
const targets = new Array(); class CLIFunctionsRepository {
function CliFunction(key, description) { static PushCliFunction(target, propertyKey, descriptor, key, description) {
return function (target, propertyKey, descriptor) { CLIFunctionsRepository.targets.push({
targets.push({
target, target,
propertyKey, propertyKey,
descriptor, descriptor,
key, key,
description, description,
}); });
};
} }
exports.CliFunction = CliFunction; static GetCliFunctions(key) {
function GetCliFunctions(key) { const results = CLIFunctionsRepository.targets.find((x) => x.key === key);
const results = targets.find((x) => x.key === key);
if (results === undefined || results.length === 0) { if (results === undefined || results.length === 0) {
throw new Error(`no CLI mode found for ${key}`); throw new Error(`no CLI mode found for ${key}`);
} }
return results; return results;
} }
exports.GetCliFunctions = GetCliFunctions; static GetAllCliModes() {
function GetAllCliModes() { return CLIFunctionsRepository.targets.map((x) => {
return targets.map((x) => {
return { return {
key: x.key, key: x.key,
description: x.description, description: x.description,
}; };
}); });
} }
exports.GetAllCliModes = GetAllCliModes; // eslint-disable-next-line no-unused-vars
static PushCliFunctionSource(cliFunction) { }
}
exports.CLIFunctionsRepository = CLIFunctionsRepository;
CLIFunctionsRepository.targets = [];
function CliFunction(key, description) {
return (target, propertyKey, descriptor) => {
CLIFunctionsRepository.PushCliFunction(target, propertyKey, descriptor, key, description);
};
}
exports.CliFunction = CliFunction;
/***/ }), /***/ }),
@ -494,8 +500,12 @@ const __1 = __nccwpck_require__(41359);
const core = __importStar(__nccwpck_require__(42186)); const core = __importStar(__nccwpck_require__(42186));
const action_yaml_1 = __nccwpck_require__(11091); const action_yaml_1 = __nccwpck_require__(11091);
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855)); const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
const cli_decorator_1 = __nccwpck_require__(8731);
const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(31011)); const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(31011));
const cli_functions_repository_1 = __nccwpck_require__(85301);
const aws_cli_commands_1 = __nccwpck_require__(6371);
const caching_1 = __nccwpck_require__(32885);
const lfs_hashing_1 = __nccwpck_require__(85204);
const setup_cloud_runner_repository_1 = __nccwpck_require__(68258);
class CLI { class CLI {
static get cliMode() { static get cliMode() {
return CLI.options !== undefined && CLI.options.mode !== undefined && CLI.options.mode !== ''; return CLI.options !== undefined && CLI.options.mode !== undefined && CLI.options.mode !== '';
@ -510,6 +520,10 @@ class CLI {
return; return;
} }
static InitCliMode() { static InitCliMode() {
cli_functions_repository_1.CLIFunctionsRepository.PushCliFunctionSource(aws_cli_commands_1.AWSCLICommands);
cli_functions_repository_1.CLIFunctionsRepository.PushCliFunctionSource(caching_1.Caching);
cli_functions_repository_1.CLIFunctionsRepository.PushCliFunctionSource(lfs_hashing_1.LFSHashing);
cli_functions_repository_1.CLIFunctionsRepository.PushCliFunctionSource(setup_cloud_runner_repository_1.SetupCloudRunnerRepository);
const program = new commander_ts_1.Command(); const program = new commander_ts_1.Command();
program.version('0.0.1'); program.version('0.0.1');
const properties = Object.getOwnPropertyNames(__1.Input); const properties = Object.getOwnPropertyNames(__1.Input);
@ -517,7 +531,7 @@ class CLI {
for (const element of properties) { for (const element of properties) {
program.option(`--${element} <${element}>`, actionYamlReader.GetActionYamlValue(element)); program.option(`--${element} <${element}>`, actionYamlReader.GetActionYamlValue(element));
} }
program.option('-m, --mode <mode>', cli_decorator_1.GetAllCliModes() program.option('-m, --mode <mode>', cli_functions_repository_1.CLIFunctionsRepository.GetAllCliModes()
.map((x) => `${x.key} (${x.description})`) .map((x) => `${x.key} (${x.description})`)
.join(` | `)); .join(` | `));
program.option('--populateOverride <populateOverride>', 'should use override query to pull input false by default'); program.option('--populateOverride <populateOverride>', 'should use override query to pull input false by default');
@ -535,7 +549,7 @@ class CLI {
yield cloud_runner_query_override_1.default.PopulateQueryOverrideInput(); yield cloud_runner_query_override_1.default.PopulateQueryOverrideInput();
} }
CLI.logInput(); CLI.logInput();
const results = cli_decorator_1.GetCliFunctions(CLI.options.mode); const results = cli_functions_repository_1.CLIFunctionsRepository.GetCliFunctions(CLI.options.mode);
cloud_runner_logger_1.default.log(`Entrypoint: ${results.key}`); cloud_runner_logger_1.default.log(`Entrypoint: ${results.key}`);
CLI.options.versioning = 'None'; CLI.options.versioning = 'None';
return yield results.target[results.propertyKey](); return yield results.target[results.propertyKey]();
@ -566,10 +580,10 @@ class CLI {
} }
} }
__decorate([ __decorate([
cli_decorator_1.CliFunction(`print-input`, `prints all input`) cli_functions_repository_1.CliFunction(`print-input`, `prints all input`)
], CLI, "logInput", null); ], CLI, "logInput", null);
__decorate([ __decorate([
cli_decorator_1.CliFunction(`cli`, `runs a cloud runner build`) cli_functions_repository_1.CliFunction(`cli`, `runs a cloud runner build`)
], CLI, "CLIBuild", null); ], CLI, "CLIBuild", null);
exports.CLI = CLI; exports.CLI = CLI;
@ -1196,6 +1210,71 @@ class AWSTaskRunner {
exports["default"] = AWSTaskRunner; exports["default"] = AWSTaskRunner;
/***/ }),
/***/ 6371:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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.AWSCLICommands = void 0;
const aws_sdk_1 = __importDefault(__nccwpck_require__(71786));
const cli_functions_repository_1 = __nccwpck_require__(85301);
const input_1 = __importDefault(__nccwpck_require__(91933));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
class AWSCLICommands {
static garbageCollectAws() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
process.env.AWS_REGION = input_1.default.region;
cloud_runner_logger_1.default.log(`Cloud Formation stacks`);
const CF = new aws_sdk_1.default.CloudFormation();
const stacks = ((_a = (yield CF.listStacks().promise()).StackSummaries) === null || _a === void 0 ? void 0 : _a.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE')) || [];
for (const element of stacks) {
cloud_runner_logger_1.default.log(JSON.stringify(element, undefined, 4));
if (input_1.default.cloudRunnerTests)
yield CF.deleteStack({ StackName: element.StackName }).promise();
}
cloud_runner_logger_1.default.log(`ECS Clusters`);
const ecs = new aws_sdk_1.default.ECS();
const clusters = (yield ecs.listClusters().promise()).clusterArns || [];
if (stacks === undefined) {
return;
}
for (const element of clusters) {
const input = {
cluster: element,
};
cloud_runner_logger_1.default.log(JSON.stringify(yield ecs.listTasks(input).promise(), undefined, 4));
}
});
}
}
__decorate([
cli_functions_repository_1.CliFunction(`garbage-collect-aws`, `garbage collect aws`)
], AWSCLICommands, "garbageCollectAws", null);
exports.AWSCLICommands = AWSCLICommands;
/***/ }), /***/ }),
/***/ 68083: /***/ 68083:
@ -2421,6 +2500,179 @@ class CloudRunnerError {
exports.CloudRunnerError = CloudRunnerError; exports.CloudRunnerError = CloudRunnerError;
/***/ }),
/***/ 32885:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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 = __nccwpck_require__(96206);
const fs_1 = __importDefault(__nccwpck_require__(57147));
const path_1 = __importDefault(__nccwpck_require__(71017));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
const cloud_runner_folders_1 = __nccwpck_require__(13527);
const cloud_runner_system_1 = __nccwpck_require__(46920);
const lfs_hashing_1 = __nccwpck_require__(85204);
const remote_client_logger_1 = __nccwpck_require__(59412);
const cli_1 = __nccwpck_require__(55651);
const cli_functions_repository_1 = __nccwpck_require__(85301);
class Caching {
static cachePush() {
return __awaiter(this, void 0, void 0, function* () {
try {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
cloud_runner_1.default.buildParameters = buildParameter;
yield Caching.PushToCache(cli_1.CLI.options['cachePushTo'], cli_1.CLI.options['cachePushFrom'], cli_1.CLI.options['artifactName'] || '');
}
catch (error) {
cloud_runner_logger_1.default.log(`${error}`);
}
});
}
static cachePull() {
return __awaiter(this, void 0, void 0, function* () {
try {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
cloud_runner_1.default.buildParameters = buildParameter;
yield Caching.PullFromCache(cli_1.CLI.options['cachePushFrom'], cli_1.CLI.options['cachePushTo'], cli_1.CLI.options['artifactName'] || '');
}
catch (error) {
cloud_runner_logger_1.default.log(`${error}`);
}
});
}
static PushToCache(cacheFolder, sourceFolder, cacheArtifactName) {
return __awaiter(this, void 0, void 0, function* () {
cacheArtifactName = cacheArtifactName.replace(' ', '');
const startPath = process.cwd();
try {
if (!fs_1.default.existsSync(cacheFolder)) {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cacheFolder}`);
}
process.chdir(path_1.default.resolve(sourceFolder, '..'));
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) {
cloud_runner_logger_1.default.log(`Hashed cache folder ${yield lfs_hashing_1.LFSHashing.hashAllFiles(sourceFolder)} ${sourceFolder} ${path_1.default.basename(sourceFolder)}`);
}
// eslint-disable-next-line func-style
const formatFunction = function (format) {
const arguments_ = Array.prototype.slice.call([path_1.default.resolve(sourceFolder, '..'), cacheFolder, cacheArtifactName], 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
};
yield cloud_runner_system_1.CloudRunnerSystem.Run(`zip -q ${cacheArtifactName}.zip ${path_1.default.basename(sourceFolder)}`);
console_1.assert(fs_1.default.existsSync(`${cacheArtifactName}.zip`), 'cache zip exists');
console_1.assert(fs_1.default.existsSync(path_1.default.basename(sourceFolder)), 'source folder exists');
if (cloud_runner_1.default.buildParameters.cachePushOverrideCommand) {
cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(cloud_runner_1.default.buildParameters.cachePushOverrideCommand));
}
cloud_runner_system_1.CloudRunnerSystem.Run(`mv ${cacheArtifactName}.zip ${cacheFolder}`);
remote_client_logger_1.RemoteClientLogger.log(`moved ${cacheArtifactName}.zip to ${cacheFolder}`);
console_1.assert(fs_1.default.existsSync(`${path_1.default.join(cacheFolder, cacheArtifactName)}.zip`), 'cache zip exists inside cache folder');
}
catch (error) {
process.chdir(`${startPath}`);
throw error;
}
process.chdir(`${startPath}`);
});
}
static PullFromCache(cacheFolder, destinationFolder, cacheArtifactName = ``) {
return __awaiter(this, void 0, void 0, function* () {
cacheArtifactName = cacheArtifactName.replace(' ', '');
const startPath = process.cwd();
remote_client_logger_1.RemoteClientLogger.log(`Caching for ${path_1.default.basename(destinationFolder)}`);
try {
if (!fs_1.default.existsSync(cacheFolder)) {
fs_1.default.mkdirSync(cacheFolder);
}
if (!fs_1.default.existsSync(destinationFolder)) {
fs_1.default.mkdirSync(destinationFolder);
}
const latestInBranch = yield (yield cloud_runner_system_1.CloudRunnerSystem.Run(`ls -t "${cacheFolder}" | grep .zip$ | head -1`))
.replace(/\n/g, ``)
.replace('.zip', '');
process.chdir(cacheFolder);
const cacheSelection = cacheArtifactName !== `` && fs_1.default.existsSync(`${cacheArtifactName}.zip`) ? cacheArtifactName : latestInBranch;
yield cloud_runner_logger_1.default.log(`cache key ${cacheArtifactName} selection ${cacheSelection}`);
// eslint-disable-next-line func-style
const formatFunction = function (format) {
const arguments_ = Array.prototype.slice.call([path_1.default.resolve(destinationFolder, '..'), cacheFolder, cacheArtifactName], 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
};
if (cloud_runner_1.default.buildParameters.cachePullOverrideCommand) {
cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(cloud_runner_1.default.buildParameters.cachePullOverrideCommand));
}
if (fs_1.default.existsSync(`${cacheSelection}.zip`)) {
const resultsFolder = `results${cloud_runner_1.default.buildParameters.buildGuid}`;
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${resultsFolder}`);
remote_client_logger_1.RemoteClientLogger.log(`cache item exists ${cacheFolder}/${cacheSelection}.zip`);
console_1.assert(`${fs_1.default.existsSync(destinationFolder)}`, `destination folder to pull into exists`);
const fullResultsFolder = path_1.default.join(cacheFolder, resultsFolder);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`unzip -q ${cacheSelection}.zip -d ${path_1.default.basename(resultsFolder)}`);
remote_client_logger_1.RemoteClientLogger.log(`cache item extracted to ${fullResultsFolder}`);
console_1.assert(`${fs_1.default.existsSync(fullResultsFolder)}`, `cache extraction results folder exists`);
const destinationParentFolder = path_1.default.resolve(destinationFolder, '..');
if (fs_1.default.existsSync(destinationFolder)) {
fs_1.default.rmSync(destinationFolder, { recursive: true, force: true });
}
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mv "${fullResultsFolder}/${path_1.default.basename(destinationFolder)}" "${destinationParentFolder}"`);
}
else {
remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheArtifactName} doesn't exist ${destinationFolder}`);
if (cacheSelection !== ``) {
remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheArtifactName}.zip doesn't exist ${destinationFolder}`);
throw new Error(`Failed to get cache item, but cache hit was found: ${cacheSelection}`);
}
}
}
catch (error) {
process.chdir(`${startPath}`);
throw error;
}
process.chdir(`${startPath}`);
});
}
static handleCachePurging() {
if (process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined) {
remote_client_logger_1.RemoteClientLogger.log(`purging ${cloud_runner_folders_1.CloudRunnerFolders.purgeRemoteCaching}`);
fs_1.default.rmdirSync(cloud_runner_folders_1.CloudRunnerFolders.cacheFolder, { recursive: true });
}
}
}
__decorate([
cli_functions_repository_1.CliFunction(`cache-push`, `push to cache`)
], Caching, "cachePush", null);
__decorate([
cli_functions_repository_1.CliFunction(`cache-pull`, `pull from cache`)
], Caching, "cachePull", null);
exports.Caching = Caching;
/***/ }), /***/ }),
/***/ 46920: /***/ 46920:
@ -2488,6 +2740,88 @@ class CloudRunnerSystem {
exports.CloudRunnerSystem = CloudRunnerSystem; exports.CloudRunnerSystem = CloudRunnerSystem;
/***/ }),
/***/ 85204:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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(__nccwpck_require__(71017));
const cloud_runner_folders_1 = __nccwpck_require__(13527);
const cloud_runner_system_1 = __nccwpck_require__(46920);
const fs_1 = __importDefault(__nccwpck_require__(57147));
const console_1 = __nccwpck_require__(96206);
const cli_1 = __nccwpck_require__(55651);
const cli_functions_repository_1 = __nccwpck_require__(85301);
class LFSHashing {
static createLFSHashFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
yield cloud_runner_system_1.CloudRunnerSystem.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_folders_1.CloudRunnerFolders.repoPathFull, `.lfs-assets-guid`)}`, 'utf8')
.replace(/\n/g, ``),
lfsGuidSum: fs_1.default
.readFileSync(`${path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.repoPathFull, `.lfs-assets-guid-sum`)}`, 'utf8')
.replace(' .lfs-assets-guid', '')
.replace(/\n/g, ``),
};
return lfsHashes;
}
catch (error) {
throw error;
}
});
}
static hashAllFiles(folder) {
return __awaiter(this, void 0, void 0, function* () {
const startPath = process.cwd();
process.chdir(folder);
const result = yield (yield cloud_runner_system_1.CloudRunnerSystem.Run(`find -type f -exec md5sum "{}" + | sort | md5sum`))
.replace(/\n/g, '')
.split(` `)[0];
process.chdir(startPath);
return result;
});
}
static hash() {
return __awaiter(this, void 0, void 0, function* () {
const folder = cli_1.CLI.options['cachePushFrom'];
LFSHashing.hashAllFiles(folder);
});
}
}
__decorate([
cli_functions_repository_1.CliFunction(`hash`, `hash all folder contents`)
], LFSHashing, "hash", null);
exports.LFSHashing = LFSHashing;
/***/ }), /***/ }),
/***/ 59412: /***/ 59412:
@ -2518,6 +2852,128 @@ class RemoteClientLogger {
exports.RemoteClientLogger = RemoteClientLogger; exports.RemoteClientLogger = RemoteClientLogger;
/***/ }),
/***/ 68258:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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(__nccwpck_require__(57147));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const cloud_runner_folders_1 = __nccwpck_require__(13527);
const caching_1 = __nccwpck_require__(32885);
const lfs_hashing_1 = __nccwpck_require__(85204);
const cloud_runner_system_1 = __nccwpck_require__(46920);
const remote_client_logger_1 = __nccwpck_require__(59412);
const path_1 = __importDefault(__nccwpck_require__(71017));
const console_1 = __nccwpck_require__(96206);
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
const cli_functions_repository_1 = __nccwpck_require__(85301);
class SetupCloudRunnerRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cloud_runner_folders_1.CloudRunnerFolders.buildPathFull}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cloud_runner_folders_1.CloudRunnerFolders.repoPathFull}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cloud_runner_folders_1.CloudRunnerFolders.cacheFolderFull}`);
process.chdir(cloud_runner_folders_1.CloudRunnerFolders.repoPathFull);
yield SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles();
yield SetupCloudRunnerRepository.sizeOfFolder('repo before lfs cache pull', cloud_runner_folders_1.CloudRunnerFolders.repoPathFull);
const lfsHashes = yield lfs_hashing_1.LFSHashing.createLFSHashFiles();
if (fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.libraryFolderFull)) {
remote_client_logger_1.RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
}
yield caching_1.Caching.PullFromCache(cloud_runner_folders_1.CloudRunnerFolders.lfsCacheFolderFull, cloud_runner_folders_1.CloudRunnerFolders.lfsDirectoryFull, `${lfsHashes.lfsGuidSum}`);
yield SetupCloudRunnerRepository.sizeOfFolder('repo after lfs cache pull', cloud_runner_folders_1.CloudRunnerFolders.repoPathFull);
yield SetupCloudRunnerRepository.pullLatestLFS();
yield SetupCloudRunnerRepository.sizeOfFolder('repo before lfs git pull', cloud_runner_folders_1.CloudRunnerFolders.repoPathFull);
yield caching_1.Caching.PushToCache(cloud_runner_folders_1.CloudRunnerFolders.lfsCacheFolderFull, cloud_runner_folders_1.CloudRunnerFolders.lfsDirectoryFull, `${lfsHashes.lfsGuidSum}`);
yield caching_1.Caching.PullFromCache(cloud_runner_folders_1.CloudRunnerFolders.libraryCacheFolderFull, cloud_runner_folders_1.CloudRunnerFolders.libraryFolderFull);
yield SetupCloudRunnerRepository.sizeOfFolder('repo after library cache pull', cloud_runner_folders_1.CloudRunnerFolders.repoPathFull);
caching_1.Caching.handleCachePurging();
}
catch (error) {
throw error;
}
});
}
static sizeOfFolder(message, folder) {
return __awaiter(this, void 0, void 0, function* () {
cloud_runner_logger_1.default.log(`Size of ${message}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`du -sh ${folder}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`du -h ${folder}`);
});
}
static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
process.chdir(`${cloud_runner_folders_1.CloudRunnerFolders.repoPathFull}`);
remote_client_logger_1.RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global advice.detachedHead false`);
remote_client_logger_1.RemoteClientLogger.log(`Cloning the repository being built:`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process --skip"`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git clone -q ${cloud_runner_folders_1.CloudRunnerFolders.targetBuildRepoUrl} ${path_1.default.resolve(`..`, path_1.default.basename(cloud_runner_folders_1.CloudRunnerFolders.repoPathFull))}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs install`);
console_1.assert(fs_1.default.existsSync(`.git`), 'git folder exists');
remote_client_logger_1.RemoteClientLogger.log(`${cloud_runner_1.default.buildParameters.branch}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git checkout ${cloud_runner_1.default.buildParameters.branch}`);
console_1.assert(fs_1.default.existsSync(path_1.default.join(`.git`, `lfs`)), 'LFS folder should not exist before caching');
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_folders_1.CloudRunnerFolders.repoPathFull);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge -- %f"`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process"`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs pull`);
remote_client_logger_1.RemoteClientLogger.log(`pulled latest LFS files`);
console_1.assert(fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.lfsDirectoryFull));
});
}
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_1.default.buildParameters = buildParameter;
yield SetupCloudRunnerRepository.run();
});
}
}
__decorate([
cli_functions_repository_1.CliFunction(`remote-cli`, `sets up a repository, usually before a game-ci build`)
], SetupCloudRunnerRepository, "runRemoteClientJob", null);
exports.SetupCloudRunnerRepository = SetupCloudRunnerRepository;
/***/ }), /***/ }),
/***/ 71899: /***/ 71899:
@ -3606,7 +4062,7 @@ const project_1 = __importDefault(__nccwpck_require__(88666));
exports.Project = project_1.default; exports.Project = project_1.default;
const unity_1 = __importDefault(__nccwpck_require__(70498)); const unity_1 = __importDefault(__nccwpck_require__(70498));
exports.Unity = unity_1.default; exports.Unity = unity_1.default;
const versioning_1 = __importDefault(__nccwpck_require__(88729)); const versioning_1 = __importDefault(__nccwpck_require__(93901));
exports.Versioning = versioning_1.default; exports.Versioning = versioning_1.default;
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144)); const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
exports.CloudRunner = cloud_runner_1.default; exports.CloudRunner = cloud_runner_1.default;
@ -4639,7 +5095,7 @@ exports["default"] = Unity;
/***/ }), /***/ }),
/***/ 88729: /***/ 93901:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "use strict";
@ -133378,7 +133834,7 @@ Object.defineProperty(apiLoader.services['clouddirectory'], '2016-05-10', {
}); });
Object.defineProperty(apiLoader.services['clouddirectory'], '2017-01-11', { Object.defineProperty(apiLoader.services['clouddirectory'], '2017-01-11', {
get: function get() { get: function get() {
var model = __nccwpck_require__(19073); var model = __nccwpck_require__(88729);
model.paginators = (__nccwpck_require__(10156)/* .pagination */ .o); model.paginators = (__nccwpck_require__(10156)/* .pagination */ .o);
return model; return model;
}, },
@ -383833,7 +384289,7 @@ module.exports = JSON.parse('{"o":{"ListAppliedSchemaArns":{"input_token":"NextT
/***/ }), /***/ }),
/***/ 19073: /***/ 88729:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,36 +0,0 @@
// eslint-disable-next-line no-unused-vars
import { AWSCLICommands } from '../cloud-runner/cloud-runner-providers/aws/commands/aws-cli-commands';
// eslint-disable-next-line no-unused-vars
import { Caching } from '../cloud-runner/remote-client/caching';
// eslint-disable-next-line no-unused-vars
import { LFSHashing } from '../cloud-runner/remote-client/lfs-hashing';
// eslint-disable-next-line no-unused-vars
import { SetupCloudRunnerRepository } from '../cloud-runner/remote-client/setup-cloud-runner-repository';
const targets = new Array();
export function CliFunction(key: string, description: string) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
targets.push({
target,
propertyKey,
descriptor,
key,
description,
});
};
}
export function GetCliFunctions(key) {
const results = targets.find((x) => x.key === key);
if (results === undefined || results.length === 0) {
throw new Error(`no CLI mode found for ${key}`);
}
return results;
}
export function GetAllCliModes() {
return targets.map((x) => {
return {
key: x.key,
description: x.description,
};
});
}

View File

@ -0,0 +1,41 @@
export class CLIFunctionsRepository {
private static targets: any[] = [];
public static PushCliFunction(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor,
key: string,
description: string,
) {
CLIFunctionsRepository.targets.push({
target,
propertyKey,
descriptor,
key,
description,
});
}
public static GetCliFunctions(key) {
const results = CLIFunctionsRepository.targets.find((x) => x.key === key);
if (results === undefined || results.length === 0) {
throw new Error(`no CLI mode found for ${key}`);
}
return results;
}
public static GetAllCliModes() {
return CLIFunctionsRepository.targets.map((x) => {
return {
key: x.key,
description: x.description,
};
});
}
// eslint-disable-next-line no-unused-vars
public static PushCliFunctionSource(cliFunction: any) {}
}
export function CliFunction(key: string, description: string) {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
CLIFunctionsRepository.PushCliFunction(target, propertyKey, descriptor, key, description);
};
}

View File

@ -3,8 +3,12 @@ import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
import * as core from '@actions/core'; import * as core from '@actions/core';
import { ActionYamlReader } from '../input-readers/action-yaml'; import { ActionYamlReader } from '../input-readers/action-yaml';
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger'; import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger';
import { CliFunction, GetAllCliModes, GetCliFunctions } from './cli-decorator';
import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override'; import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override';
import { CliFunction, CLIFunctionsRepository } from './cli-functions-repository';
import { AWSCLICommands } from '../cloud-runner/cloud-runner-providers/aws/commands/aws-cli-commands';
import { Caching } from '../cloud-runner/remote-client/caching';
import { LFSHashing } from '../cloud-runner/remote-client/lfs-hashing';
import { SetupCloudRunnerRepository } from '../cloud-runner/remote-client/setup-cloud-runner-repository';
export class CLI { export class CLI {
public static options; public static options;
@ -22,6 +26,10 @@ export class CLI {
} }
public static InitCliMode() { public static InitCliMode() {
CLIFunctionsRepository.PushCliFunctionSource(AWSCLICommands);
CLIFunctionsRepository.PushCliFunctionSource(Caching);
CLIFunctionsRepository.PushCliFunctionSource(LFSHashing);
CLIFunctionsRepository.PushCliFunctionSource(SetupCloudRunnerRepository);
const program = new Command(); const program = new Command();
program.version('0.0.1'); program.version('0.0.1');
const properties = Object.getOwnPropertyNames(Input); const properties = Object.getOwnPropertyNames(Input);
@ -31,7 +39,7 @@ export class CLI {
} }
program.option( program.option(
'-m, --mode <mode>', '-m, --mode <mode>',
GetAllCliModes() CLIFunctionsRepository.GetAllCliModes()
.map((x) => `${x.key} (${x.description})`) .map((x) => `${x.key} (${x.description})`)
.join(` | `), .join(` | `),
); );
@ -50,7 +58,7 @@ export class CLI {
await CloudRunnerQueryOverride.PopulateQueryOverrideInput(); await CloudRunnerQueryOverride.PopulateQueryOverrideInput();
} }
CLI.logInput(); CLI.logInput();
const results = GetCliFunctions(CLI.options.mode); const results = CLIFunctionsRepository.GetCliFunctions(CLI.options.mode);
CloudRunnerLogger.log(`Entrypoint: ${results.key}`); CloudRunnerLogger.log(`Entrypoint: ${results.key}`);
CLI.options.versioning = 'None'; CLI.options.versioning = 'None';
return await results.target[results.propertyKey](); return await results.target[results.propertyKey]();

View File

@ -1,5 +1,5 @@
import AWS from 'aws-sdk'; import AWS from 'aws-sdk';
import { CliFunction } from '../../../../cli/cli-decorator'; import { CliFunction } from '../../../../cli/cli-functions-repository';
import Input from '../../../../input'; import Input from '../../../../input';
import CloudRunnerLogger from '../../../services/cloud-runner-logger'; import CloudRunnerLogger from '../../../services/cloud-runner-logger';

View File

@ -8,7 +8,7 @@ import { CloudRunnerSystem } from './cloud-runner-system';
import { LFSHashing } from './lfs-hashing'; import { LFSHashing } from './lfs-hashing';
import { RemoteClientLogger } from './remote-client-logger'; import { RemoteClientLogger } from './remote-client-logger';
import { CLI } from '../../cli/cli'; import { CLI } from '../../cli/cli';
import { CliFunction } from '../../cli/cli-decorator'; import { CliFunction } from '../../cli/cli-functions-repository';
export class Caching { export class Caching {
@CliFunction(`cache-push`, `push to cache`) @CliFunction(`cache-push`, `push to cache`)

View File

@ -4,7 +4,7 @@ import { CloudRunnerSystem } from './cloud-runner-system';
import fs from 'fs'; import fs from 'fs';
import { assert } from 'console'; import { assert } from 'console';
import { CLI } from '../../cli/cli'; import { CLI } from '../../cli/cli';
import { CliFunction } from '../../cli/cli-decorator'; import { CliFunction } from '../../cli/cli-functions-repository';
export class LFSHashing { export class LFSHashing {
public static async createLFSHashFiles() { public static async createLFSHashFiles() {

View File

@ -8,7 +8,7 @@ import { RemoteClientLogger } from './remote-client-logger';
import path from 'path'; import path from 'path';
import { assert } from 'console'; import { assert } from 'console';
import CloudRunnerLogger from '../services/cloud-runner-logger'; import CloudRunnerLogger from '../services/cloud-runner-logger';
import { CliFunction } from '../../cli/cli-decorator'; import { CliFunction } from '../../cli/cli-functions-repository';
export class SetupCloudRunnerRepository { export class SetupCloudRunnerRepository {
public static async run() { public static async run() {