From 124dc2196ddf81817ab88bc1fe9ec3ee563747b1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jan 2024 16:55:51 +0100 Subject: [PATCH] Show daemon log output in setup --- dist/index.js | 25 +++++++++++++++---------- src/index.ts | 28 +++++++++++++++++----------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index 798ea7a..0a1acc3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12146,6 +12146,15 @@ async function fetchAutoCacher() { const last_path = paths.at(-2); return `${last_path}/bin/magic-nix-cache`; } +function tailLog(daemonDir) { + const log = new Tail_1(path$1.join(daemonDir, 'daemon.log')); + coreExports.debug(`tailing daemon.log...`); + log.on('line', (line) => { + //core.debug(`got a log line`); + coreExports.info(line); + }); + return log; +} async function setUpAutoCache() { const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir(); const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN']; @@ -12182,6 +12191,7 @@ async function setUpAutoCache() { // Start the server. Once it is ready, it will notify us via file descriptor 3. const outputPath = `${daemonDir}/daemon.log`; const output = openSync(outputPath, 'a'); + const log = tailLog(daemonDir); const notifyFd = 3; const daemon = spawn(daemonBin, [ '--notify-fd', String(notifyFd), @@ -12210,21 +12220,21 @@ async function setUpAutoCache() { } }); daemon.on('exit', async (code, signal) => { - const log = await fs$2.readFile(outputPath, 'utf-8'); if (signal) { - reject(new Error(`Daemon was killed by signal ${signal}: ${log}`)); + reject(new Error(`Daemon was killed by signal ${signal}`)); } else if (code) { - reject(new Error(`Daemon exited with code ${code}: ${log}`)); + reject(new Error(`Daemon exited with code ${code}`)); } else { - reject(new Error(`Daemon unexpectedly exited: ${log}`)); + reject(new Error(`Daemon unexpectedly exited`)); } }); }); daemon.unref(); coreExports.info('Launched Magic Nix Cache'); coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); + log.unwatch(); } async function notifyAutoCache() { const daemonDir = process.env[ENV_CACHE_DAEMONDIR]; @@ -12255,12 +12265,7 @@ async function tearDownAutoCache() { if (!pid) { throw new Error("magic-nix-cache did not start successfully"); } - const log = new Tail_1(path$1.join(daemonDir, 'daemon.log')); - coreExports.debug(`tailing daemon.log...`); - log.on('line', (line) => { - coreExports.debug(`got a log line`); - coreExports.info(line); - }); + const log = tailLog(daemonDir); try { coreExports.debug(`about to post to localhost`); const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json(); diff --git a/src/index.ts b/src/index.ts index 4542dab..e767125 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,6 +72,16 @@ async function fetchAutoCacher() { return `${last_path}/bin/magic-nix-cache`; } +function tailLog(daemonDir) { + const log = new Tail(path.join(daemonDir, 'daemon.log')); + core.debug(`tailing daemon.log...`); + log.on('line', (line) => { + //core.debug(`got a log line`); + core.info(line); + }); + return log; +} + async function setUpAutoCache() { const tmpdir = process.env['RUNNER_TEMP'] || os.tmpdir(); const required_env = ['ACTIONS_CACHE_URL', 'ACTIONS_RUNTIME_URL', 'ACTIONS_RUNTIME_TOKEN']; @@ -113,6 +123,7 @@ async function setUpAutoCache() { // Start the server. Once it is ready, it will notify us via file descriptor 3. const outputPath = `${daemonDir}/daemon.log`; const output = openSync(outputPath, 'a'); + const log = tailLog(daemonDir); const notifyFd = 3; const daemon = spawn( daemonBin, @@ -150,13 +161,12 @@ async function setUpAutoCache() { }); daemon.on('exit', async (code, signal) => { - const log: string = await fs.readFile(outputPath, 'utf-8'); if (signal) { - reject(new Error(`Daemon was killed by signal ${signal}: ${log}`)); + reject(new Error(`Daemon was killed by signal ${signal}`)); } else if (code) { - reject(new Error(`Daemon exited with code ${code}: ${log}`)); + reject(new Error(`Daemon exited with code ${code}`)); } else { - reject(new Error(`Daemon unexpectedly exited: ${log}`)); + reject(new Error(`Daemon unexpectedly exited`)); } }); }); @@ -165,6 +175,8 @@ async function setUpAutoCache() { core.info('Launched Magic Nix Cache'); core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); + + log.unwatch(); } async function notifyAutoCache() { @@ -201,13 +213,7 @@ async function tearDownAutoCache() { throw new Error("magic-nix-cache did not start successfully"); } - const log = new Tail(path.join(daemonDir, 'daemon.log')); - core.debug(`tailing daemon.log...`); - log.on('line', (line) => { - core.debug(`got a log line`); - core.info(line); - }); - + const log = tailLog(daemonDir); try { core.debug(`about to post to localhost`);