stream logs through standard input and new remote client cli command

pull/531/head
Frostebite 2023-06-04 21:07:01 +01:00
parent 16284dcf8d
commit 8a501a6c9f
5 changed files with 51 additions and 3 deletions

24
dist/index.js generated vendored
View File

@ -526,6 +526,7 @@ class Cli {
program.option('--cachePushTo <cachePushTo>', 'cache push to caching folder');
program.option('--artifactName <artifactName>', 'caching artifact name');
program.option('--select <select>', 'select a particular resource');
program.option('--logFile <logFile>', 'output to log file (log stream only)');
program.parse(process.argv);
Cli.options = program.opts();
return Cli.isCliMode;
@ -4295,6 +4296,7 @@ const cloud_runner_system_1 = __nccwpck_require__(4197);
const yaml_1 = __importDefault(__nccwpck_require__(44603));
const github_1 = __importDefault(__nccwpck_require__(39789));
const build_parameters_1 = __importDefault(__nccwpck_require__(80787));
const cli_1 = __nccwpck_require__(55651);
class RemoteClient {
static async setupRemoteClient() {
cloud_runner_logger_1.default.log(`bootstrap game ci cloud runner...`);
@ -4304,6 +4306,23 @@ class RemoteClient {
await RemoteClient.replaceLargePackageReferencesWithSharedReferences();
await RemoteClient.runCustomHookFiles(`before-build`);
}
static async remoteClientLogStream() {
const logFile = cli_1.Cli.options['logFile'];
process.stdin.resume();
process.stdin.setEncoding('utf8');
let lingeringLine = '';
process.stdin.on('data', (chunk) => {
const lines = chunk.toString().split('\n');
lines[0] = lingeringLine + lines[0];
lingeringLine = lines.pop() || '';
for (const element of lines) {
node_fs_1.default.appendFileSync(logFile, element);
}
});
process.stdin.on('end', function () {
node_fs_1.default.appendFileSync(logFile, lingeringLine);
});
}
static async remoteClientPostBuild() {
remote_client_logger_1.RemoteClientLogger.log(`Running POST build tasks`);
await caching_1.Caching.PushToCache(cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(`${cloud_runner_folders_1.CloudRunnerFolders.cacheFolderForCacheKeyFull}/Library`), cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(cloud_runner_folders_1.CloudRunnerFolders.libraryFolderAbsolute), `lib-${cloud_runner_1.default.buildParameters.buildGuid}`);
@ -4437,6 +4456,9 @@ class RemoteClient {
__decorate([
cli_functions_repository_1.CliFunction(`remote-cli-pre-build`, `sets up a repository, usually before a game-ci build`)
], RemoteClient, "setupRemoteClient", null);
__decorate([
cli_functions_repository_1.CliFunction('remote-cli-log-stream', `log stream from standard input`)
], RemoteClient, "remoteClientLogStream", null);
__decorate([
cli_functions_repository_1.CliFunction(`remote-cli-post-build`, `runs a cloud runner build`)
], RemoteClient, "remoteClientPostBuild", null);
@ -5708,7 +5730,7 @@ node ${builderPath} -m remote-cli-pre-build`;
chmod -R +x "/steps"
echo "game ci start"
echo "game ci start" >> /home/job-log.txt
/entrypoint.sh | tee /home/build-log.txt
/entrypoint.sh | node ${builderPath} -m remote-cli-log-stream /home/build-log.txt
cat /home/build-log.txt >> /home/job-log.txt
node ${builderPath} -m remote-cli-post-build`;
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -52,6 +52,7 @@ export class Cli {
program.option('--cachePushTo <cachePushTo>', 'cache push to caching folder');
program.option('--artifactName <artifactName>', 'caching artifact name');
program.option('--select <select>', 'select a particular resource');
program.option('--logFile <logFile>', 'output to log file (log stream only)');
program.parse(process.argv);
Cli.options = program.opts();

View File

@ -12,6 +12,7 @@ import { CloudRunnerSystem } from '../services/core/cloud-runner-system';
import YAML from 'yaml';
import GitHub from '../../github';
import BuildParameters from '../../build-parameters';
import { Cli } from '../../cli/cli';
export class RemoteClient {
@CliFunction(`remote-cli-pre-build`, `sets up a repository, usually before a game-ci build`)
@ -24,6 +25,30 @@ export class RemoteClient {
await RemoteClient.runCustomHookFiles(`before-build`);
}
@CliFunction('remote-cli-log-stream', `log stream from standard input`)
public static async remoteClientLogStream() {
const logFile = Cli.options!['logFile'];
process.stdin.resume();
process.stdin.setEncoding('utf8');
let lingeringLine = '';
process.stdin.on('data', (chunk) => {
const lines = chunk.toString().split('\n');
lines[0] = lingeringLine + lines[0];
lingeringLine = lines.pop() || '';
for (const element of lines) {
fs.appendFileSync(logFile, element);
}
});
process.stdin.on('end', function () {
fs.appendFileSync(logFile, lingeringLine);
});
}
@CliFunction(`remote-cli-post-build`, `runs a cloud runner build`)
public static async remoteClientPostBuild(): Promise<string> {
RemoteClientLogger.log(`Running POST build tasks`);

View File

@ -110,7 +110,7 @@ node ${builderPath} -m remote-cli-pre-build`;
chmod -R +x "/steps"
echo "game ci start"
echo "game ci start" >> /home/job-log.txt
/entrypoint.sh | tee /home/build-log.txt
/entrypoint.sh | node ${builderPath} -m remote-cli-log-stream /home/build-log.txt
cat /home/build-log.txt >> /home/job-log.txt
node ${builderPath} -m remote-cli-post-build`;
}