diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf490e7..b2c28c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,19 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - test: + test-starts: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run TurboRepo Remote Cache Server + uses: ./ + with: + storage-provider: local + storage-path: turbo-cache + + test-realistic: runs-on: ubuntu-latest env: TURBO_TELEMETRY_DISABLED: 1 @@ -66,4 +78,4 @@ jobs: - name: Error if prior step succeeded if: steps.run-turbo.outcome == 'success' - run: exit 1 + run: exit 1 \ No newline at end of file diff --git a/dist/post/index.js b/dist/post/index.js index c08519f..edd81f5 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -2783,14 +2783,6 @@ 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 -const 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" @@ -2824,7 +2816,6 @@ const readLog = async (name) => { - function pidIsRunning(pid) { try { process.kill(pid, 0); @@ -2834,6 +2825,14 @@ 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')); diff --git a/dist/server/index.cjs b/dist/server/index.cjs index cdfecb7..83dc272 100644 --- a/dist/server/index.cjs +++ b/dist/server/index.cjs @@ -218186,14 +218186,6 @@ module.exports = require("net"); /***/ }), -/***/ 87561: -/***/ ((module) => { - -"use strict"; -module.exports = require("node:fs"); - -/***/ }), - /***/ 22037: /***/ ((module) => { @@ -233688,51 +233680,6 @@ function createApp(options = {}) { /***/ }), -/***/ 2604: -/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => { - -"use strict"; -// ESM COMPAT FLAG -__nccwpck_require__.r(__webpack_exports__); - -// EXPORTS -__nccwpck_require__.d(__webpack_exports__, { - "logFile": () => (/* binding */ logFile), - "readLog": () => (/* binding */ readLog) -}); - -// EXTERNAL MODULE: external "node:fs" -var external_node_fs_ = __nccwpck_require__(87561); -;// CONCATENATED MODULE: external "node:fs/promises" -const promises_namespaceObject = require("node:fs/promises"); -;// CONCATENATED MODULE: external "node:path" -const external_node_path_namespaceObject = require("node:path"); -// EXTERNAL MODULE: external "os" -var external_os_ = __nccwpck_require__(22037); -;// CONCATENATED MODULE: ./src/logs.js - - - - - -const logDir = external_node_path_namespaceObject.resolve(external_os_.tmpdir(), 'turborepo-remote-cache-gh-action'); - -if (!external_node_fs_.existsSync(logDir)) { - external_node_fs_.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 ''; - } -}; - -/***/ }), - /***/ 14625: /***/ ((module) => { @@ -240286,33 +240233,16 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { -const fs = __nccwpck_require__(87561); -const { logFile } = __nccwpck_require__(2604); +const { createApp } = __nccwpck_require__(21968); -const handleError = (err) => { - fs.writeFileSync(logFile('err'), err.message); - process.exit(1); -}; +const app = createApp({trustProxy: true}); -try { - const { createApp } = __nccwpck_require__(21968); - - const app = createApp({ - trustProxy: true, - logger: { - level: 'debug', - stream: fs.createWriteStream(logFile('out')), - }, - }); - - app.listen({ host: process.env.HOST, port: process.env.PORT }, (err) => { - if (err) { - handleError(err); - } - }); -} catch (err) { - handleError(err); -} +app.listen({ host: process.env.HOST, port: process.env.PORT }, (err) => { + if (err) { + console.error(err); + process.exit(1); + } +}); })(); diff --git a/dist/start/index.js b/dist/start/index.js index 57a952e..fdd99d3 100644 --- a/dist/start/index.js +++ b/dist/start/index.js @@ -6042,14 +6042,6 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path"); // EXTERNAL MODULE: ./node_modules/.pnpm/tcp-port-used@1.0.2/node_modules/tcp-port-used/index.js var tcp_port_used = __nccwpck_require__(8351); -;// CONCATENATED MODULE: ./src/indentMultiline.js -const 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 @@ -6069,33 +6061,6 @@ 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 @@ -6104,8 +6069,6 @@ const readLog = async (name) => { - - async function getPort() { if (port) { (0,core.debug)(`Using specified port: ${port}`); @@ -6125,7 +6088,7 @@ async function main() { (0,core.debug)('Starting Turbo Cache Server...'); const subprocess = (0,external_node_child_process_namespaceObject.spawn)( 'node', - [(0,external_node_path_namespaceObject.resolve)(process.cwd(), 'dist/server/index.cjs')], + [(0,external_node_path_namespaceObject.resolve)(process.cwd(), 'dist/start_and_log')], { detached: true, stdio: 'ignore', @@ -6156,9 +6119,7 @@ async function main() { (0,core.exportVariable)('TURBO_TOKEN', token); (0,core.exportVariable)('TURBO_TEAM', teamId); } catch (e) { - const errors = await readLog('err'); - const errorMessage = errors ? `\nErrors: ${indentMultiline(errors)}` : ''; - throw new Error(`Turbo server failed to start on port: ${port}${errorMessage}`); + throw new Error(`Turbo server failed to start on port: ${port}`); } } diff --git a/dist/start_and_log/index.js b/dist/start_and_log/index.js new file mode 100644 index 0000000..1f40f9a --- /dev/null +++ b/dist/start_and_log/index.js @@ -0,0 +1,49 @@ +import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module"; +/******/ /* webpack/runtime/compat */ +/******/ +/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; + +;// CONCATENATED MODULE: external "node:child_process" +const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:child_process"); +;// CONCATENATED MODULE: external "node:fs" +const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); +;// CONCATENATED MODULE: external "node:path" +const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path"); +;// CONCATENATED MODULE: external "node:fs/promises" +const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs/promises"); +;// CONCATENATED MODULE: external "os" +const external_os_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("os"); +;// CONCATENATED MODULE: ./src/logs.js + + + + + +const logDir = external_node_path_namespaceObject.resolve(external_os_namespaceObject.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 fsPromises.readFile(logFile(name), 'utf8'); + } catch (e) { + return ''; + } +}; +;// CONCATENATED MODULE: ./src/start_and_log.js + + + + + +const subprocess = (0,external_node_child_process_namespaceObject.spawn)('node', [(0,external_node_path_namespaceObject.resolve)(process.cwd(), 'dist/server/index.cjs')], {env: process.env, stdio: 'pipe'}); + +subprocess.stdout.pipe((0,external_node_fs_namespaceObject.createWriteStream)(logFile('out'))); +subprocess.stderr.pipe((0,external_node_fs_namespaceObject.createWriteStream)(logFile('err'))); diff --git a/dist/start_and_log/package.json b/dist/start_and_log/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/dist/start_and_log/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/package.json b/package.json index 24ea7d3..b086fe1 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "clean": "rimraf dist", "build": "npm-run-all clean --parallel build:*", "build:start": "ncc build src/start.js -o dist/start", + "build:start_and_log": "ncc build src/start_and_log.js -o dist/start_and_log", "build:server": "ncc build src/server.cjs -o dist/server", "build:post": "ncc build src/post.js -o dist/post", "turbo:test": "echo 'Hello, world!'" diff --git a/src/indentMultiline.js b/src/indentMultiline.js deleted file mode 100644 index b7b9bca..0000000 --- a/src/indentMultiline.js +++ /dev/null @@ -1,7 +0,0 @@ -export const 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 3d22668..97d6c3b 100644 --- a/src/post.js +++ b/src/post.js @@ -1,5 +1,4 @@ import { debug, getState, info, setFailed } from '@actions/core'; -import { indentMultiline } from './indentMultiline.js'; import { readLog } from './logs.js'; function pidIsRunning(pid) { @@ -11,6 +10,14 @@ 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')); diff --git a/src/server.cjs b/src/server.cjs index 539e231..4d57188 100644 --- a/src/server.cjs +++ b/src/server.cjs @@ -1,27 +1,10 @@ -const fs = require('node:fs'); -const { logFile } = require('./logs.js'); +const { createApp } = require('turborepo-remote-cache'); -const handleError = (err) => { - fs.writeFileSync(logFile('err'), err.message); - process.exit(1); -}; +const app = createApp({trustProxy: true}); -try { - const { createApp } = require('turborepo-remote-cache'); - - const app = createApp({ - trustProxy: true, - logger: { - level: 'debug', - stream: fs.createWriteStream(logFile('out')), - }, - }); - - app.listen({ host: process.env.HOST, port: process.env.PORT }, (err) => { - if (err) { - handleError(err); - } - }); -} catch (err) { - handleError(err); -} +app.listen({ host: process.env.HOST, port: process.env.PORT }, (err) => { + if (err) { + console.error(err); + process.exit(1); + } +}); diff --git a/src/start.js b/src/start.js index 6269403..55603be 100644 --- a/src/start.js +++ b/src/start.js @@ -9,9 +9,7 @@ import getFreePort from 'get-port'; import { spawn } from 'node:child_process'; import { resolve } from 'node:path'; import { waitUntilUsedOnHost } from 'tcp-port-used'; -import { indentMultiline } from './indentMultiline.js'; import { host, port, storagePath, storageProvider, teamId, token } from './inputs.js'; -import { readLog } from './logs.js'; async function getPort() { if (port) { @@ -32,7 +30,7 @@ async function main() { debug('Starting Turbo Cache Server...'); const subprocess = spawn( 'node', - [resolve(process.cwd(), 'dist/server/index.cjs')], + [resolve(process.cwd(), 'dist/start_and_log')], { detached: true, stdio: 'ignore', @@ -63,9 +61,7 @@ async function main() { exportVariable('TURBO_TOKEN', token); exportVariable('TURBO_TEAM', teamId); } catch (e) { - const errors = await readLog('err'); - const errorMessage = errors ? `\nErrors: ${indentMultiline(errors)}` : ''; - throw new Error(`Turbo server failed to start on port: ${port}${errorMessage}`); + throw new Error(`Turbo server failed to start on port: ${port}`); } } diff --git a/src/start_and_log.js b/src/start_and_log.js new file mode 100644 index 0000000..a202bb5 --- /dev/null +++ b/src/start_and_log.js @@ -0,0 +1,9 @@ +import { spawn } from 'node:child_process'; +import { createWriteStream } from 'node:fs'; +import { resolve } from 'node:path'; +import { logFile } from './logs.js'; + +const subprocess = spawn('node', [resolve(process.cwd(), 'dist/server/index.cjs')], {env: process.env, stdio: 'pipe'}); + +subprocess.stdout.pipe(createWriteStream(logFile('out'))); +subprocess.stderr.pipe(createWriteStream(logFile('err'))); \ No newline at end of file