Logging improvement

pull/310/head
Frostebite 2021-12-27 22:16:09 +00:00
parent 1d7a50a0b8
commit cafabf6c7d
6 changed files with 94 additions and 90 deletions

172
dist/index.js vendored
View File

@ -455,15 +455,15 @@ 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);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
class Caching {
static PushToCache(cacheFolder, destinationFolder, artifactName) {
return __awaiter(this, void 0, void 0, function* () {
try {
process.chdir(`${destinationFolder}/..`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`zip -r "${artifactName}.zip" "${path_1.default.dirname(destinationFolder)}"`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`zip -r "${artifactName}.zip" "${path_1.default.dirname(destinationFolder)}"`);
console_1.assert(fs_1.default.existsSync(`${artifactName}.zip`));
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`cp "${artifactName}.zip" "${path_1.default.join(cacheFolder, `${artifactName}.zip`)}"`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`cp "${artifactName}.zip" "${path_1.default.join(cacheFolder, `${artifactName}.zip`)}"`);
cloud_runner_logger_1.default.logCli(`copied ${artifactName} to ${cacheFolder}`);
}
catch (error) {
@ -475,12 +475,12 @@ class Caching {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!fs_1.default.existsSync(cacheFolder)) {
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cacheFolder}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${cacheFolder}`);
}
if (!fs_1.default.existsSync(destinationFolder)) {
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${destinationFolder}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`mkdir -p ${destinationFolder}`);
}
const latest = yield (yield remote_client_system_1.CloudRunnerAgentSystem.Run(`ls -t "${cacheFolder}" | grep .zip$ | head -1`)).replace(`\n`, ``);
const latest = yield (yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -t "${cacheFolder}" | grep .zip$ | head -1`)).replace(`\n`, ``);
process.chdir(cacheFolder);
let cacheSelection;
if (specificHashMatch !== ``) {
@ -491,9 +491,9 @@ class Caching {
}
if (fs_1.default.existsSync(cacheSelection)) {
cloud_runner_logger_1.default.logCli(`Library cache exists`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`unzip "${cacheSelection}" -d "${destinationFolder}"`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`unzip "${cacheSelection}" -d "${destinationFolder}"`);
console_1.assert(fs_1.default.existsSync(destinationFolder));
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
}
else {
cloud_runner_logger_1.default.logCli(`Library cache doesn't exist`);
@ -515,7 +515,7 @@ class Caching {
}
static printCacheState(lfsCacheFolder, libraryCacheFolder) {
return __awaiter(this, void 0, void 0, function* () {
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`echo ' '
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`echo ' '
echo "LFS cache for $branch"
du -sch "${lfsCacheFolder}/"
echo '**'
@ -534,6 +534,64 @@ class Caching {
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerAgentSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class CloudRunnerAgentSystem {
static Run(command) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((promise) => {
let output = '';
const child = child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
cloud_runner_logger_1.default.logCli(`[ERROR] ${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
cloud_runner_logger_1.default.logCli(`[DIAGNOSTIC] ${stderr.toString()}`);
return;
}
const outputChunk = `${stdout}`;
output += outputChunk;
});
child.on('close', function (code) {
cloud_runner_logger_1.default.logCli(`[Exit code ${code}]`);
if (code !== 0) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
for (const element of outputLines) {
cloud_runner_logger_1.default.logCli(element);
}
promise(output);
});
});
});
}
}
exports.CloudRunnerAgentSystem = CloudRunnerAgentSystem;
/***/ }),
/***/ 21811:
@ -562,7 +620,7 @@ const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const caching_1 = __webpack_require__(35010);
const lfs_hashing_1 = __webpack_require__(47011);
const remote_client_system_1 = __webpack_require__(91269);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
class CloudRunnerRepositorySetup {
static run() {
return __awaiter(this, void 0, void 0, function* () {
@ -575,19 +633,19 @@ class CloudRunnerRepositorySetup {
yield lfs_hashing_1.LFSHashing.printLFSHashState();
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.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
cloud_runner_logger_1.default.logCli(`Library Caching`);
console_1.assert(fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull), `!Warning!: The Unity library was included in the git repository`);
yield caching_1.Caching.PullFromCache(libraryCacheFolder, cloud_runner_state_1.CloudRunnerState.libraryFolderFull);
cloud_runner_logger_1.default.logCli(`LFS Caching`);
yield caching_1.Caching.PullFromCache(lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, `${CloudRunnerRepositorySetup.LFS_ASSETS_HASH}.zip`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield caching_1.Caching.printCacheState(lfsCacheFolder, libraryCacheFolder);
yield CloudRunnerRepositorySetup.pullLatestLFS();
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}`);
yield caching_1.Caching.PushToCache(lfsCacheFolder, cloud_runner_state_1.CloudRunnerState.lfsDirectory, CloudRunnerRepositorySetup.LFS_ASSETS_HASH);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${cloud_runner_state_1.CloudRunnerState.cacheFolderFull}`);
caching_1.Caching.handleCachePurging();
}
catch (error) {
@ -600,15 +658,15 @@ class CloudRunnerRepositorySetup {
try {
cloud_runner_logger_1.default.logCli(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logCli(`Cloning the repository being built:`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
cloud_runner_logger_1.default.logCli(cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git clone ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`tree`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git clone ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree`);
cloud_runner_logger_1.default.logCli(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
cloud_runner_logger_1.default.logCli(`Checked out ${process.env.GITHUB_SHA}`);
}
catch (error) {
@ -619,7 +677,7 @@ class CloudRunnerRepositorySetup {
static pullLatestLFS() {
return __awaiter(this, void 0, void 0, function* () {
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git lfs pull`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs pull`);
cloud_runner_logger_1.default.logCli(`pulled latest LFS files`);
});
}
@ -686,12 +744,12 @@ 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 remote_client_system_1 = __webpack_require__(91269);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const fs_1 = __importDefault(__webpack_require__(35747));
class LFSHashing {
static printLFSHashState() {
return __awaiter(this, void 0, void 0, function* () {
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`echo ' '
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`echo ' '
echo 'Contents of .lfs-assets-guid file:'
cat .lfs-assets-guid
echo ' '
@ -706,9 +764,11 @@ class LFSHashing {
static createLFSHashFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
yield remote_client_system_1.CloudRunnerAgentSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
return fs_1.default.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8');
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`);
return fs_1.default
.readFileSync(`${path_1.default.join(cloud_runner_state_1.CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8')
.replace('\n', '');
}
catch (error) {
throw error;
@ -719,64 +779,6 @@ class LFSHashing {
exports.LFSHashing = LFSHashing;
/***/ }),
/***/ 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.CloudRunnerAgentSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class CloudRunnerAgentSystem {
static Run(command) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((promise) => {
let output = '';
const child = child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
cloud_runner_logger_1.default.logCli(`[ERROR] ${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
cloud_runner_logger_1.default.logCli(`[DIAGNOSTIC] ${stderr.toString()}`);
return;
}
const outputChunk = `${stdout}`;
output += outputChunk;
});
child.on('close', function (code) {
cloud_runner_logger_1.default.logCli(`[Exit code ${code}]`);
if (code !== 0) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
for (const element of outputLines) {
cloud_runner_logger_1.default.logCli(element);
}
promise(output);
});
});
});
}
}
exports.CloudRunnerAgentSystem = CloudRunnerAgentSystem;
/***/ }),
/***/ 28730:

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ import fs from 'fs';
import path from 'path';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerAgentSystem } from './remote-client-system';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
export class Caching {
public static async PushToCache(cacheFolder: string, destinationFolder: string, artifactName: string) {

View File

@ -5,7 +5,7 @@ import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { Caching } from './caching';
import { LFSHashing } from './lfs-hashing';
import { CloudRunnerAgentSystem } from './remote-client-system';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
export class CloudRunnerRepositorySetup {
static LFS_ASSETS_HASH;

View File

@ -1,6 +1,6 @@
import path from 'path';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerAgentSystem } from './remote-client-system';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
import fs from 'fs';
export class LFSHashing {
@ -23,7 +23,9 @@ export class LFSHashing {
try {
await CloudRunnerAgentSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
await CloudRunnerAgentSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
return fs.readFileSync(`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8');
return fs
.readFileSync(`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8')
.replace('\n', '');
} catch (error) {
throw error;
}