diff --git a/dist/post/index.js b/dist/post/index.js index edd81f5..f9fc75b 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -2783,6 +2783,14 @@ var __webpack_exports__ = {}; // EXTERNAL MODULE: ./node_modules/.pnpm/@actions+core@1.10.1/node_modules/@actions/core/lib/core.js var core = __nccwpck_require__(93); +;// CONCATENATED MODULE: ./src/indentMultiline.js +function indentMultiline(message, spaces = 2) { + const output = []; + message.split('\n').forEach((line) => { + output.push(' '.repeat(spaces) + line); + }); + return output.join('\n'); +} ;// CONCATENATED MODULE: external "node:fs" const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); ;// CONCATENATED MODULE: external "node:fs/promises" @@ -2816,6 +2824,7 @@ const readLog = async (name) => { + function pidIsRunning(pid) { try { process.kill(pid, 0); @@ -2825,30 +2834,18 @@ function pidIsRunning(pid) { } } -function indentMultiline(message, spaces = 2) { - const output = []; - message.split('\n').forEach((line) => { - output.push(' '.repeat(spaces) + line); - }); - return output.join('\n'); -} - async function post() { const pid = parseInt((0,core.getState)('pid')); + if (isNaN(pid)) return; + if (pidIsRunning(pid)) { (0,core.info)(`Stopping Turbo Cache Server with PID ${pid}`); process.kill(pid); } else { - if (isNaN(pid)) { - (0,core.setFailed)( - 'Turbo Cache Server was not running. This probably indicates that the server was unable to start.', - ); - } else { - (0,core.setFailed)( - `Turbo Cache Server with PID ${pid} was not running. This may indicate a configuration or server crash.`, - ); - } + (0,core.setFailed)( + `Turbo Cache Server with PID ${pid} was not running. This may indicate a configuration or server crash.`, + ); } const [out, err] = await Promise.all([readLog('out'), readLog('err')]); diff --git a/dist/start/index.js b/dist/start/index.js index 7c2aa01..1cac178 100644 --- a/dist/start/index.js +++ b/dist/start/index.js @@ -6044,6 +6044,14 @@ const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(impo var tcp_port_used = __nccwpck_require__(8351); ;// CONCATENATED MODULE: external "url" const external_url_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("url"); +;// CONCATENATED MODULE: ./src/indentMultiline.js +function indentMultiline(message, spaces = 2) { + const output = []; + message.split('\n').forEach((line) => { + output.push(' '.repeat(spaces) + line); + }); + return output.join('\n'); +} // EXTERNAL MODULE: external "crypto" var external_crypto_ = __nccwpck_require__(6113); ;// CONCATENATED MODULE: ./src/inputs.js @@ -6063,6 +6071,33 @@ const token = (0,external_crypto_.randomBytes)(24).toString('hex'); const host = (0,core.getInput)('host', { trimWhitespace: true }); const port = parseInt((0,core.getInput)('port', { trimWhitespace: true })); +;// CONCATENATED MODULE: external "node:fs" +const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); +;// CONCATENATED MODULE: external "node:fs/promises" +const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs/promises"); +// EXTERNAL MODULE: external "os" +var external_os_ = __nccwpck_require__(2037); +;// CONCATENATED MODULE: ./src/logs.js + + + + + +const logDir = external_node_path_namespaceObject.resolve(external_os_.tmpdir(), 'turborepo-remote-cache-gh-action'); + +if (!external_node_fs_namespaceObject.existsSync(logDir)) { + external_node_fs_namespaceObject.mkdirSync(logDir, { recursive: true }); +} + +const logFile = (name) => external_node_path_namespaceObject.resolve(logDir, name); + +const readLog = async (name) => { + try { + return await promises_namespaceObject.readFile(logFile(name), 'utf8'); + } catch (e) { + return ''; + } +}; ;// CONCATENATED MODULE: ./src/start.js @@ -6072,6 +6107,8 @@ const port = parseInt((0,core.getInput)('port', { trimWhitespace: true })); + + const start_dirname = (0,external_node_path_namespaceObject.dirname)((0,external_url_namespaceObject.fileURLToPath)(import.meta.url)); async function getPort() { @@ -6127,7 +6164,9 @@ async function main() { process.exit(0); } catch (e) { - throw new Error(`Turbo server failed to start on port: ${port}\n${e}`); + const errors = await readLog('err'); + const errorMessage = errors ? `\nErrors:\n${indentMultiline(errors)}` : ''; + throw new Error(`Turbo server failed to start on port: ${port}\n${errorMessage}`); } } diff --git a/src/indentMultiline.js b/src/indentMultiline.js new file mode 100644 index 0000000..de32b7a --- /dev/null +++ b/src/indentMultiline.js @@ -0,0 +1,7 @@ +export function indentMultiline(message, spaces = 2) { + const output = []; + message.split('\n').forEach((line) => { + output.push(' '.repeat(spaces) + line); + }); + return output.join('\n'); +} \ No newline at end of file diff --git a/src/post.js b/src/post.js index 97d6c3b..1ddf929 100644 --- a/src/post.js +++ b/src/post.js @@ -1,4 +1,5 @@ import { debug, getState, info, setFailed } from '@actions/core'; +import { indentMultiline } from './indentMultiline.js'; import { readLog } from './logs.js'; function pidIsRunning(pid) { @@ -10,30 +11,18 @@ function pidIsRunning(pid) { } } -function indentMultiline(message, spaces = 2) { - const output = []; - message.split('\n').forEach((line) => { - output.push(' '.repeat(spaces) + line); - }); - return output.join('\n'); -} - async function post() { const pid = parseInt(getState('pid')); + if (isNaN(pid)) return; + if (pidIsRunning(pid)) { info(`Stopping Turbo Cache Server with PID ${pid}`); process.kill(pid); } else { - if (isNaN(pid)) { - setFailed( - 'Turbo Cache Server was not running. This probably indicates that the server was unable to start.', - ); - } else { - setFailed( - `Turbo Cache Server with PID ${pid} was not running. This may indicate a configuration or server crash.`, - ); - } + setFailed( + `Turbo Cache Server with PID ${pid} was not running. This may indicate a configuration or server crash.`, + ); } const [out, err] = await Promise.all([readLog('out'), readLog('err')]); diff --git a/src/start.js b/src/start.js index 19ede76..a1f4b8c 100644 --- a/src/start.js +++ b/src/start.js @@ -10,7 +10,9 @@ import { spawn } from 'node:child_process'; import { dirname, resolve } from 'node:path'; import { waitUntilUsedOnHost } from 'tcp-port-used'; import { fileURLToPath } from 'url'; +import { indentMultiline } from './indentMultiline.js'; import { host, port, storagePath, storageProvider, teamId, token } from './inputs.js'; +import { readLog } from './logs.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -67,7 +69,9 @@ async function main() { process.exit(0); } catch (e) { - throw new Error(`Turbo server failed to start on port: ${port}\n${e}`); + const errors = await readLog('err'); + const errorMessage = errors ? `\nErrors:\n${indentMultiline(errors)}` : ''; + throw new Error(`Turbo server failed to start on port: ${port}\n${errorMessage}`); } }