Skip to content

Commit

Permalink
Switch back to start and log method
Browse files Browse the repository at this point in the history
  • Loading branch information
trappar committed Feb 15, 2024
1 parent ad90c75 commit ffaee97
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 169 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,4 +78,4 @@ jobs:

- name: Error if prior step succeeded
if: steps.run-turbo.outcome == 'success'
run: exit 1
run: exit 1
17 changes: 8 additions & 9 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2824,7 +2816,6 @@ const readLog = async (name) => {




function pidIsRunning(pid) {
try {
process.kill(pid, 0);
Expand All @@ -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'));

Expand Down
86 changes: 8 additions & 78 deletions dist/server/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -218186,14 +218186,6 @@ module.exports = require("net");

/***/ }),

/***/ 87561:
/***/ ((module) => {

"use strict";
module.exports = require("node:fs");

/***/ }),

/***/ 22037:
/***/ ((module) => {

Expand Down Expand Up @@ -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) => {

Expand Down Expand Up @@ -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);
}
});

})();

Expand Down
43 changes: 2 additions & 41 deletions dist/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -6104,8 +6069,6 @@ const readLog = async (name) => {





async function getPort() {
if (port) {
(0,core.debug)(`Using specified port: ${port}`);
Expand All @@ -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',
Expand Down Expand Up @@ -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}`);
}
}

Expand Down
49 changes: 49 additions & 0 deletions dist/start_and_log/index.js
Original file line number Diff line number Diff line change
@@ -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')));
3 changes: 3 additions & 0 deletions dist/start_and_log/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!'"
Expand Down
7 changes: 0 additions & 7 deletions src/indentMultiline.js

This file was deleted.

9 changes: 8 additions & 1 deletion src/post.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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'));

Expand Down
33 changes: 8 additions & 25 deletions src/server.cjs
Original file line number Diff line number Diff line change
@@ -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);
}
});
Loading

0 comments on commit ffaee97

Please sign in to comment.