Refactor CLI/cleanup

pull/310/head
Frostebite 2021-12-25 19:35:09 +00:00
parent 92e4c11048
commit 0077a33392
8 changed files with 408 additions and 327 deletions

581
dist/index.js vendored
View File

@ -46,8 +46,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__webpack_require__(42186));
const model_1 = __webpack_require__(41359);
const commander_ts_1 = __webpack_require__(40451);
const remote_client_1 = __webpack_require__(48135);
const cli_1 = __webpack_require__(55651);
function runMain() {
return __awaiter(this, void 0, void 0, function* () {
try {
@ -77,44 +76,15 @@ function runMain() {
}
});
}
function runCli() {
return __awaiter(this, void 0, void 0, function* () {
options.versioning = 'None';
model_1.Input.cliOptions = options;
const buildParameter = yield model_1.BuildParameters.create();
const baseImage = new model_1.ImageTag(buildParameter);
yield model_1.CloudRunner.run(buildParameter, baseImage.toString());
});
}
model_1.Input.githubEnabled = false;
const program = new commander_ts_1.Command();
program.version('0.0.1');
const properties = Object.getOwnPropertyNames(model_1.Input);
core.info(`\r\n`);
core.info(`INPUT:`);
for (const element of properties) {
program.option(`--${element} <${element}>`, 'default description');
if (model_1.Input[element] !== undefined && model_1.Input[element] !== '') {
core.info(`${element} ${model_1.Input[element]}`);
}
}
core.info(`\r\n`);
program.option('-m, --mode <mode>', 'cli or default');
program.parse(process.argv);
const options = program.opts();
const options = cli_1.CLI.SetupCli();
// eslint-disable-next-line no-console
console.log(`Entrypoint: ${options.mode}`);
switch (options.mode) {
case 'cli':
runCli();
break;
case 'remote-cli':
remote_client_1.RemoteClientCli.RunRemoteClient(options);
break;
default:
if (cli_1.CLI.isCliMode(options)) {
cli_1.CLI.RunCli(options);
}
else {
model_1.Input.githubEnabled = true;
runMain();
break;
}
@ -375,6 +345,317 @@ class Cache {
exports.default = Cache;
/***/ }),
/***/ 55651:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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.CLI = void 0;
const commander_ts_1 = __webpack_require__(40451);
const __1 = __webpack_require__(41359);
const core = __importStar(__webpack_require__(42186));
const remote_client_1 = __webpack_require__(95575);
class CLI {
static RunCli(options) {
return __awaiter(this, void 0, void 0, function* () {
if (options.mode === 'remote-cli') {
yield remote_client_1.RemoteClient.Run(options);
}
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());
}
});
}
static isCliMode(options) {
switch (options.mode) {
case 'cli':
case 'remote-cli':
return true;
default:
return false;
}
}
static SetupCli() {
__1.Input.githubEnabled = false;
const program = new commander_ts_1.Command();
program.version('0.0.1');
const properties = Object.getOwnPropertyNames(__1.Input);
core.info(`\r\n`);
core.info(`INPUT:`);
for (const element of properties) {
program.option(`--${element} <${element}>`, 'default description');
if (__1.Input[element] !== undefined && __1.Input[element] !== '') {
core.info(`${element} ${__1.Input[element]}`);
}
}
core.info(`\r\n`);
program.option('-m, --mode <mode>', 'cli or default');
program.parse(process.argv);
return program.opts();
}
}
exports.CLI = CLI;
/***/ }),
/***/ 95575:
/***/ (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.RemoteClient = void 0;
const cloud_runner_state_1 = __webpack_require__(70912);
const setup_repo_1 = __webpack_require__(42959);
class RemoteClient {
static Run(options) {
return __awaiter(this, void 0, void 0, function* () {
const buildParameter = JSON.parse(process.env.buildParameters || '{}');
cloud_runner_state_1.CloudRunnerState.setup(buildParameter);
switch (options.remoteClientState) {
default:
yield setup_repo_1.DownloadRepository.run();
break;
}
});
}
}
exports.RemoteClient = RemoteClient;
/***/ }),
/***/ 91269:
/***/ (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.RemoteClientSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class RemoteClientSystem {
static Run(command) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((promise) => {
child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
cloud_runner_logger_1.default.logRemoteCli(`[ERROR] ${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
cloud_runner_logger_1.default.logRemoteCli(`[STD-ERROR] ${stderr}`);
throw new Error(stderr.toString());
}
cloud_runner_logger_1.default.logRemoteCli(`${stdout}`);
promise(stdout);
});
});
});
}
}
exports.RemoteClientSystem = RemoteClientSystem;
/***/ }),
/***/ 42959:
/***/ (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.DownloadRepository = void 0;
const fs_1 = __importDefault(__webpack_require__(35747));
const path_1 = __importDefault(__webpack_require__(85622));
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const remote_client_system_1 = __webpack_require__(91269);
class DownloadRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
fs_1.default.mkdirSync(cloud_runner_state_1.CloudRunnerState.buildPathFull);
fs_1.default.mkdirSync(cloud_runner_state_1.CloudRunnerState.repoPathFull);
cloud_runner_logger_1.default.logRemoteCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
// stop annoying git detatched head info
yield remote_client_system_1.RemoteClientSystem.Run(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logRemoteCli(`Cloning the repository being built:`);
yield remote_client_system_1.RemoteClientSystem.Run(`git lfs install --skip-smudge`);
cloud_runner_logger_1.default.logRemoteCli(cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl);
yield remote_client_system_1.RemoteClientSystem.Run(`
git clone --progress --verbose ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}
`);
yield remote_client_system_1.RemoteClientSystem.Run(`
git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.gitSha}
`);
cloud_runner_logger_1.default.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`);
yield remote_client_system_1.RemoteClientSystem.Run(`
git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid
`);
yield remote_client_system_1.RemoteClientSystem.Run(`
md5sum .lfs-assets-guid > .lfs-assets-guid-sum
`);
const LFS_ASSETS_HASH = fs_1.default.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8');
yield remote_client_system_1.RemoteClientSystem.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 ${cloud_runner_state_1.CloudRunnerState.projectPathFull}
echo ' '
`);
const lfsCacheFolder = path_1.default.join(cloud_runner_state_1.CloudRunnerState.cacheFolderFull, `lfs`);
const libraryCacheFolder = path_1.default.join(cloud_runner_state_1.CloudRunnerState.cacheFolderFull, `lib`);
yield remote_client_system_1.RemoteClientSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.builderPathFull}`);
cloud_runner_logger_1.default.logRemoteCli(`Starting checks of cache for the Unity project Library and git LFS files`);
if (!fs_1.default.existsSync(lfsCacheFolder)) {
fs_1.default.mkdirSync(lfsCacheFolder);
}
if (!fs_1.default.existsSync(libraryCacheFolder)) {
fs_1.default.mkdirSync(libraryCacheFolder);
}
cloud_runner_logger_1.default.logRemoteCli(`Library Caching`);
//if the unity git project has included the library delete it and echo a warning
if (fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull)) {
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull, { recursive: true });
cloud_runner_logger_1.default.logRemoteCli(`!Warning!: The Unity library was included in the git repository (this isn't usually a good practice)`);
}
//Restore library cache
const latestLibraryCacheFile = yield remote_client_system_1.RemoteClientSystem.Run(`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`);
yield remote_client_system_1.RemoteClientSystem.Run(`ls -lh "${libraryCacheFolder}"`);
cloud_runner_logger_1.default.logRemoteCli(`Checking if Library cache ${libraryCacheFolder}/${latestLibraryCacheFile} exists`);
if (fs_1.default.existsSync(latestLibraryCacheFile)) {
cloud_runner_logger_1.default.logRemoteCli(`Library cache exists`);
yield remote_client_system_1.RemoteClientSystem.Run(`
unzip -q "${path_1.default.join(libraryCacheFolder, latestLibraryCacheFile)}" -d "$projectPathFull"
tree "${cloud_runner_state_1.CloudRunnerState.libraryFolderFull}"
`);
}
cloud_runner_logger_1.default.logRemoteCli(` `);
cloud_runner_logger_1.default.logRemoteCli(`LFS Caching`);
process.chdir(lfsCacheFolder);
let latestLFSCacheFile;
if (fs_1.default.existsSync(`${LFS_ASSETS_HASH}.zip`)) {
cloud_runner_logger_1.default.logRemoteCli(`Match found: using large file hash match ${LFS_ASSETS_HASH}.zip`);
latestLFSCacheFile = `${LFS_ASSETS_HASH}.zip`;
}
else {
latestLFSCacheFile = yield remote_client_system_1.RemoteClientSystem.Run(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
}
if (fs_1.default.existsSync(latestLFSCacheFile)) {
cloud_runner_logger_1.default.logRemoteCli(`LFS cache exists`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.lfsDirectory, { recursive: true });
cloud_runner_logger_1.default.logRemoteCli(`LFS cache exists from build $latestLFSCacheFile from $branch`);
yield remote_client_system_1.RemoteClientSystem.Run(`unzip -q "${lfsCacheFolder}/${latestLFSCacheFile}" -d "${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.git`)}"`);
yield remote_client_system_1.RemoteClientSystem.Run(`ls -lh "${cloud_runner_state_1.CloudRunnerState.lfsDirectory}"`);
cloud_runner_logger_1.default.logRemoteCli(`git LFS folder, (should not contain $latestLFSCacheFile)`);
}
yield remote_client_system_1.RemoteClientSystem.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 "${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}/"
echo '**'
echo 'Full cache'
du -sch "${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}/"
echo ' '
`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield remote_client_system_1.RemoteClientSystem.Run(`git lfs pull`);
cloud_runner_logger_1.default.logRemoteCli(`pulled latest LFS files`);
process.chdir(`${cloud_runner_state_1.CloudRunnerState.lfsDirectory}/..`);
yield remote_client_system_1.RemoteClientSystem.Run(`zip -r "${LFS_ASSETS_HASH}.zip" "./lfs"`);
fs_1.default.copyFileSync(`${LFS_ASSETS_HASH}.zip`, lfsCacheFolder);
cloud_runner_logger_1.default.logRemoteCli(`copied ${LFS_ASSETS_HASH} to ${lfsCacheFolder}`);
if (process.env.purgeRemoteCaching !== undefined) {
cloud_runner_logger_1.default.logRemoteCli(`purging ${cloud_runner_state_1.CloudRunnerState.purgeRemoteCaching}`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.cacheFolder, { recursive: true });
}
});
}
}
exports.DownloadRepository = DownloadRepository;
/***/ }),
/***/ 28730:
@ -1984,230 +2265,6 @@ class KubernetesUtilities {
exports.default = KubernetesUtilities;
/***/ }),
/***/ 48135:
/***/ (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.RemoteClientCli = void 0;
const cloud_runner_state_1 = __webpack_require__(70912);
const setup_repo_1 = __webpack_require__(35323);
class RemoteClientCli {
static RunRemoteClient(options) {
return __awaiter(this, void 0, void 0, function* () {
const buildParameter = JSON.parse(process.env.buildParameters || '{}');
cloud_runner_state_1.CloudRunnerState.setup(buildParameter);
switch (options.remoteClientState) {
default:
yield setup_repo_1.DownloadRepository.run();
break;
}
});
}
}
exports.RemoteClientCli = RemoteClientCli;
/***/ }),
/***/ 35323:
/***/ (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.DownloadRepository = void 0;
const cloud_runner_state_1 = __webpack_require__(70912);
const run_cli_1 = __webpack_require__(33639);
const fs_1 = __importDefault(__webpack_require__(35747));
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const path_1 = __importDefault(__webpack_require__(85622));
class DownloadRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
fs_1.default.mkdirSync(cloud_runner_state_1.CloudRunnerState.buildPathFull);
fs_1.default.mkdirSync(cloud_runner_state_1.CloudRunnerState.repoPathFull);
cloud_runner_logger_1.default.logRemoteCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
// stop annoying git detatched head info
yield run_cli_1.RunCli.RunCli(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logRemoteCli(`Cloning the repository being built:`);
yield run_cli_1.RunCli.RunCli(`git lfs install --skip-smudge`);
cloud_runner_logger_1.default.logRemoteCli(cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl);
yield run_cli_1.RunCli.RunCli(`
git clone --progress --verbose ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}
`);
yield run_cli_1.RunCli.RunCli(`
git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.gitSha}
`);
cloud_runner_logger_1.default.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`);
yield run_cli_1.RunCli.RunCli(`
git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid
`);
yield run_cli_1.RunCli.RunCli(`
md5sum .lfs-assets-guid > .lfs-assets-guid-sum
`);
const LFS_ASSETS_HASH = fs_1.default.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8');
yield run_cli_1.RunCli.RunCli(`
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 ${cloud_runner_state_1.CloudRunnerState.projectPathFull}
echo ' '
`);
const lfsCacheFolder = path_1.default.join(cloud_runner_state_1.CloudRunnerState.cacheFolderFull, `lfs`);
const libraryCacheFolder = path_1.default.join(cloud_runner_state_1.CloudRunnerState.cacheFolderFull, `lib`);
yield run_cli_1.RunCli.RunCli(`tree ${cloud_runner_state_1.CloudRunnerState.builderPathFull}`);
cloud_runner_logger_1.default.logRemoteCli(`Starting checks of cache for the Unity project Library and git LFS files`);
if (!fs_1.default.existsSync(lfsCacheFolder)) {
fs_1.default.mkdirSync(lfsCacheFolder);
}
if (!fs_1.default.existsSync(libraryCacheFolder)) {
fs_1.default.mkdirSync(libraryCacheFolder);
}
cloud_runner_logger_1.default.logRemoteCli(`Library Caching`);
//if the unity git project has included the library delete it and echo a warning
if (fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull)) {
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull, { recursive: true });
cloud_runner_logger_1.default.logRemoteCli(`!Warning!: The Unity library was included in the git repository (this isn't usually a good practice)`);
}
//Restore library cache
const latestLibraryCacheFile = yield run_cli_1.RunCli.RunCli(`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`);
yield run_cli_1.RunCli.RunCli(`ls -lh "${libraryCacheFolder}"`);
cloud_runner_logger_1.default.logRemoteCli(`Checking if Library cache ${libraryCacheFolder}/${latestLibraryCacheFile} exists`);
if (fs_1.default.existsSync(latestLibraryCacheFile)) {
cloud_runner_logger_1.default.logRemoteCli(`Library cache exists`);
yield run_cli_1.RunCli.RunCli(`
unzip -q "${path_1.default.join(libraryCacheFolder, latestLibraryCacheFile)}" -d "$projectPathFull"
tree "${cloud_runner_state_1.CloudRunnerState.libraryFolderFull}"
`);
}
cloud_runner_logger_1.default.logRemoteCli(` `);
cloud_runner_logger_1.default.logRemoteCli(`LFS Caching`);
process.chdir(lfsCacheFolder);
let latestLFSCacheFile;
if (fs_1.default.existsSync(`${LFS_ASSETS_HASH}.zip`)) {
cloud_runner_logger_1.default.logRemoteCli(`Match found: using large file hash match ${LFS_ASSETS_HASH}.zip`);
latestLFSCacheFile = `${LFS_ASSETS_HASH}.zip`;
}
else {
latestLFSCacheFile = yield run_cli_1.RunCli.RunCli(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
}
if (fs_1.default.existsSync(latestLFSCacheFile)) {
cloud_runner_logger_1.default.logRemoteCli(`LFS cache exists`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.lfsDirectory, { recursive: true });
cloud_runner_logger_1.default.logRemoteCli(`LFS cache exists from build $latestLFSCacheFile from $branch`);
yield run_cli_1.RunCli.RunCli(`unzip -q "${lfsCacheFolder}/${latestLFSCacheFile}" -d "${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.git`)}"`);
yield run_cli_1.RunCli.RunCli(`ls -lh "${cloud_runner_state_1.CloudRunnerState.lfsDirectory}"`);
cloud_runner_logger_1.default.logRemoteCli(`git LFS folder, (should not contain $latestLFSCacheFile)`);
}
yield run_cli_1.RunCli.RunCli(`
echo ' '
echo "LFS cache for $branch"
du -sch "${lfsCacheFolder}/"
echo '**'
echo "Library cache for $branch"
du -sch "${libraryCacheFolder}/"
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 ' '
`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield run_cli_1.RunCli.RunCli(`git lfs pull`);
cloud_runner_logger_1.default.logRemoteCli(`pulled latest LFS files`);
process.chdir(`${cloud_runner_state_1.CloudRunnerState.lfsDirectory}/..`);
yield run_cli_1.RunCli.RunCli(`zip -r "${LFS_ASSETS_HASH}.zip" "./lfs"`);
fs_1.default.copyFileSync(`${LFS_ASSETS_HASH}.zip`, lfsCacheFolder);
cloud_runner_logger_1.default.logRemoteCli(`copied ${LFS_ASSETS_HASH} to ${lfsCacheFolder}`);
if (process.env.purgeRemoteCaching !== undefined) {
cloud_runner_logger_1.default.logRemoteCli(`purging ${cloud_runner_state_1.CloudRunnerState.purgeRemoteCaching}`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.cacheFolder, { recursive: true });
}
});
}
}
exports.DownloadRepository = DownloadRepository;
/***/ }),
/***/ 33639:
/***/ (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.RunCli = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class RunCli {
static RunCli(command) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((promise) => {
child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
cloud_runner_logger_1.default.logRemoteCli(`[ERROR] ${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
cloud_runner_logger_1.default.logRemoteCli(`[STD-ERROR] ${stderr}`);
throw new Error(stderr.toString());
}
cloud_runner_logger_1.default.logRemoteCli(`${stdout}`);
promise(stdout);
});
});
});
}
}
exports.RunCli = RunCli;
/***/ }),
/***/ 91311:
@ -3261,6 +3318,7 @@ class Input {
}
static get githubRepo() {
return Input.getInput('GITHUB_REPOSITORY') || 'game-ci/unity-builder';
// TODO system get repo remote?
}
static get branch() {
if (Input.getInput(`REMOTE_BUILDER_CACHE`)) {
@ -3281,6 +3339,7 @@ class Input {
else {
return 'remote-builder/unified-providers';
}
// TODO git get branch?
}
static get gitSha() {
if (Input.getInput(`GITHUB_SHA`)) {
@ -3289,6 +3348,7 @@ class Input {
if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`);
}
// TODO git get sha?
}
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
@ -3358,6 +3418,7 @@ class Input {
}
static get gitPrivateToken() {
return core.getInput('gitPrivateToken') || '';
// TODO get from git auth status -t
}
static get chownFilesTo() {
return Input.getInput('chownFilesTo') || '';

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
import * as core from '@actions/core';
import { Action, BuildParameters, Cache, Docker, ImageTag, Output, CloudRunner, Input } from './model';
import { Command } from 'commander-ts';
import { RemoteClientCli } from './model/cloud-runner/remote-client';
import { CLI } from './model/cli/cli';
async function runMain() {
try {
Action.checkCompatibility();
@ -33,43 +32,15 @@ async function runMain() {
core.setFailed((error as Error).message);
}
}
async function runCli() {
options.versioning = 'None';
Input.cliOptions = options;
const buildParameter = await BuildParameters.create();
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
}
Input.githubEnabled = false;
const program = new Command();
program.version('0.0.1');
const properties = Object.getOwnPropertyNames(Input);
core.info(`\r\n`);
core.info(`INPUT:`);
for (const element of properties) {
program.option(`--${element} <${element}>`, 'default description');
if (Input[element] !== undefined && Input[element] !== '') {
core.info(`${element} ${Input[element]}`);
}
}
core.info(`\r\n`);
program.option('-m, --mode <mode>', 'cli or default');
program.parse(process.argv);
const options = program.opts();
const options = CLI.SetupCli();
// eslint-disable-next-line no-console
console.log(`Entrypoint: ${options.mode}`);
switch (options.mode) {
case 'cli':
runCli();
break;
case 'remote-cli':
RemoteClientCli.RunRemoteClient(options);
break;
default:
if (CLI.isCliMode(options)) {
CLI.RunCli(options);
} else {
Input.githubEnabled = true;
runMain();
break;
}

View File

@ -0,0 +1,46 @@
import { Command } from 'commander-ts';
import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
import * as core from '@actions/core';
import { RemoteClient } from './remote-client';
export class CLI {
static async RunCli(options: any) {
if (options.mode === 'remote-cli') {
await RemoteClient.Run(options);
} else {
options.versioning = 'None';
Input.cliOptions = options;
const buildParameter = await BuildParameters.create();
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
}
}
static isCliMode(options: any) {
switch (options.mode) {
case 'cli':
case 'remote-cli':
return true;
default:
return false;
}
}
public static SetupCli() {
Input.githubEnabled = false;
const program = new Command();
program.version('0.0.1');
const properties = Object.getOwnPropertyNames(Input);
core.info(`\r\n`);
core.info(`INPUT:`);
for (const element of properties) {
program.option(`--${element} <${element}>`, 'default description');
if (Input[element] !== undefined && Input[element] !== '') {
core.info(`${element} ${Input[element]}`);
}
}
core.info(`\r\n`);
program.option('-m, --mode <mode>', 'cli or default');
program.parse(process.argv);
return program.opts();
}
}

View File

@ -1,8 +1,8 @@
import { CloudRunnerState } from '../state/cloud-runner-state';
import { DownloadRepository } from './remote-steps/setup-repo';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { DownloadRepository } from './setup-repo';
export class RemoteClientCli {
static async RunRemoteClient(options) {
export class RemoteClient {
static async Run(options) {
const buildParameter = JSON.parse(process.env.buildParameters || '{}');
CloudRunnerState.setup(buildParameter);
switch (options.remoteClientState) {

View File

@ -1,8 +1,8 @@
import { exec } from 'child_process';
import CloudRunnerLogger from '../services/cloud-runner-logger';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
export class RunCli {
public static async RunCli(command: string) {
export class RemoteClientSystem {
public static async Run(command: string) {
return await new Promise<string>((promise) => {
exec(command, (error, stdout, stderr) => {
if (error) {

View File

@ -1,9 +1,8 @@
import { CloudRunnerState } from '../../state/cloud-runner-state';
import { RunCli } from '../run-cli';
import fs from 'fs';
import CloudRunnerLogger from '../../services/cloud-runner-logger';
import path from 'path';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { RemoteClientSystem } from './remote-client-system';
export class DownloadRepository {
public static async run() {
@ -12,25 +11,25 @@ export class DownloadRepository {
CloudRunnerLogger.logRemoteCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(CloudRunnerState.repoPathFull);
// stop annoying git detatched head info
await RunCli.RunCli(`git config --global advice.detachedHead false`);
await RemoteClientSystem.Run(`git config --global advice.detachedHead false`);
CloudRunnerLogger.logRemoteCli(`Cloning the repository being built:`);
await RunCli.RunCli(`git lfs install --skip-smudge`);
await RemoteClientSystem.Run(`git lfs install --skip-smudge`);
CloudRunnerLogger.logRemoteCli(CloudRunnerState.targetBuildRepoUrl);
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
git clone --progress --verbose ${CloudRunnerState.targetBuildRepoUrl} ${CloudRunnerState.repoPathFull}
`);
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
git checkout ${CloudRunnerState.buildParams.gitSha}
`);
CloudRunnerLogger.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`);
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid
`);
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
md5sum .lfs-assets-guid > .lfs-assets-guid-sum
`);
const LFS_ASSETS_HASH = fs.readFileSync(`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8');
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
echo ' '
echo 'Contents of .lfs-assets-guid file:'
cat .lfs-assets-guid
@ -44,7 +43,7 @@ export class DownloadRepository {
`);
const lfsCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lfs`);
const libraryCacheFolder = path.join(CloudRunnerState.cacheFolderFull, `lib`);
await RunCli.RunCli(`tree ${CloudRunnerState.builderPathFull}`);
await RemoteClientSystem.Run(`tree ${CloudRunnerState.builderPathFull}`);
CloudRunnerLogger.logRemoteCli(`Starting checks of cache for the Unity project Library and git LFS files`);
if (!fs.existsSync(lfsCacheFolder)) {
fs.mkdirSync(lfsCacheFolder);
@ -61,12 +60,12 @@ export class DownloadRepository {
);
}
//Restore library cache
const latestLibraryCacheFile = await RunCli.RunCli(`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`);
await RunCli.RunCli(`ls -lh "${libraryCacheFolder}"`);
const latestLibraryCacheFile = await RemoteClientSystem.Run(`ls -t "${libraryCacheFolder}" | grep .zip$ | head -1`);
await RemoteClientSystem.Run(`ls -lh "${libraryCacheFolder}"`);
CloudRunnerLogger.logRemoteCli(`Checking if Library cache ${libraryCacheFolder}/${latestLibraryCacheFile} exists`);
if (fs.existsSync(latestLibraryCacheFile)) {
CloudRunnerLogger.logRemoteCli(`Library cache exists`);
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
unzip -q "${path.join(libraryCacheFolder, latestLibraryCacheFile)}" -d "$projectPathFull"
tree "${CloudRunnerState.libraryFolderFull}"
`);
@ -79,20 +78,20 @@ export class DownloadRepository {
CloudRunnerLogger.logRemoteCli(`Match found: using large file hash match ${LFS_ASSETS_HASH}.zip`);
latestLFSCacheFile = `${LFS_ASSETS_HASH}.zip`;
} else {
latestLFSCacheFile = await RunCli.RunCli(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
latestLFSCacheFile = await RemoteClientSystem.Run(`ls -t "${lfsCacheFolder}" | grep .zip$ | head -1`);
}
if (fs.existsSync(latestLFSCacheFile)) {
CloudRunnerLogger.logRemoteCli(`LFS cache exists`);
fs.rmdirSync(CloudRunnerState.lfsDirectory, { recursive: true });
CloudRunnerLogger.logRemoteCli(`LFS cache exists from build $latestLFSCacheFile from $branch`);
await RunCli.RunCli(
await RemoteClientSystem.Run(
`unzip -q "${lfsCacheFolder}/${latestLFSCacheFile}" -d "${path.join(CloudRunnerState.repoPathFull, `.git`)}"`,
);
await RunCli.RunCli(`ls -lh "${CloudRunnerState.lfsDirectory}"`);
await RemoteClientSystem.Run(`ls -lh "${CloudRunnerState.lfsDirectory}"`);
CloudRunnerLogger.logRemoteCli(`git LFS folder, (should not contain $latestLFSCacheFile)`);
}
await RunCli.RunCli(`
await RemoteClientSystem.Run(`
echo ' '
echo "LFS cache for $branch"
du -sch "${lfsCacheFolder}/"
@ -108,10 +107,10 @@ export class DownloadRepository {
echo ' '
`);
process.chdir(CloudRunnerState.repoPathFull);
await RunCli.RunCli(`git lfs pull`);
await RemoteClientSystem.Run(`git lfs pull`);
CloudRunnerLogger.logRemoteCli(`pulled latest LFS files`);
process.chdir(`${CloudRunnerState.lfsDirectory}/..`);
await RunCli.RunCli(`zip -r "${LFS_ASSETS_HASH}.zip" "./lfs"`);
await RemoteClientSystem.Run(`zip -r "${LFS_ASSETS_HASH}.zip" "./lfs"`);
fs.copyFileSync(`${LFS_ASSETS_HASH}.zip`, lfsCacheFolder);
CloudRunnerLogger.logRemoteCli(`copied ${LFS_ASSETS_HASH} to ${lfsCacheFolder}`);
if (process.env.purgeRemoteCaching !== undefined) {

View File

@ -27,6 +27,7 @@ class Input {
}
static get githubRepo(): string {
return Input.getInput('GITHUB_REPOSITORY') || 'game-ci/unity-builder';
// TODO system get repo remote?
}
static get branch() {
if (Input.getInput(`REMOTE_BUILDER_CACHE`)) {
@ -44,6 +45,7 @@ class Input {
} else {
return 'remote-builder/unified-providers';
}
// TODO git get branch?
}
static get gitSha() {
@ -53,6 +55,7 @@ class Input {
if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`);
}
// TODO git get sha?
}
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
@ -145,6 +148,7 @@ class Input {
static get gitPrivateToken() {
return core.getInput('gitPrivateToken') || '';
// TODO get from git auth status -t
}
static get chownFilesTo() {