@nrwl/nx-cloud 13.2.1 → 13.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/nx-cloud.js +7 -0
- package/bin/nx-cloud.js.map +1 -1
- package/lib/core/api/run-group.api.js +65 -1
- package/lib/core/commands/record-output.d.ts +16 -0
- package/lib/core/commands/record-output.js +200 -0
- package/lib/core/commands/record-output.js.map +1 -0
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +138 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +166 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +158 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +239 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +130 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +306 -1
- package/lib/nx-cloud-tasks-runner.js +5 -1
- package/lib/nx-cloud-tasks-runner.js.map +1 -1
- package/lib/utilities/environment.d.ts +1 -1
- package/lib/utilities/environment.js +3 -2
- package/lib/utilities/environment.js.map +1 -1
- package/package.json +4 -7
package/bin/nx-cloud.js
CHANGED
|
@@ -5,6 +5,7 @@ const distributed_agent_impl_1 = require("../lib/core/runners/distributed-agent/
|
|
|
5
5
|
const start_ci_run_1 = require("../lib/core/commands/start-ci-run");
|
|
6
6
|
const stop_all_agents_1 = require("../lib/core/commands/stop-all-agents");
|
|
7
7
|
const clean_up_agents_1 = require("../lib/core/commands/clean-up-agents");
|
|
8
|
+
const record_output_1 = require("../lib/core/commands/record-output");
|
|
8
9
|
const command = process.argv[2];
|
|
9
10
|
if (command === 'start-agent') {
|
|
10
11
|
(0, distributed_agent_impl_1.startAgent)().catch((e) => {
|
|
@@ -30,6 +31,12 @@ else if (command === 'clean-up-agents') {
|
|
|
30
31
|
process.exit(1);
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
else if (command === 'record') {
|
|
35
|
+
(0, record_output_1.runCommandAndStoreInCloud)().catch((e) => {
|
|
36
|
+
console.error(e);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
33
40
|
else {
|
|
34
41
|
console.log('Pass start-agent, stop-all-agents, or clean-up-agents');
|
|
35
42
|
}
|
package/bin/nx-cloud.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-cloud.js","sourceRoot":"","sources":["../../../../../libs/nx-packages/nx-cloud/bin/nx-cloud.ts"],"names":[],"mappings":";;;AAEA,yGAA0F;AAC1F,oEAA+D;AAC/D,0EAAqE;AACrE,0EAAqE;
|
|
1
|
+
{"version":3,"file":"nx-cloud.js","sourceRoot":"","sources":["../../../../../libs/nx-packages/nx-cloud/bin/nx-cloud.ts"],"names":[],"mappings":";;;AAEA,yGAA0F;AAC1F,oEAA+D;AAC/D,0EAAqE;AACrE,0EAAqE;AACrE,sEAA+E;AAE/E,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhC,IAAI,OAAO,KAAK,aAAa,EAAE;IAC7B,IAAA,mCAAU,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,iBAAiB,EAAE;IACxC,IAAA,+BAAa,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,cAAc,EAAE;IACrC,IAAA,yBAAU,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,iBAAiB,EAAE;IACxC,IAAA,+BAAa,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,QAAQ,EAAE;IAC/B,IAAA,yCAAyB,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;CACtE"}
|
|
@@ -1 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RunGroupApi = void 0;
|
|
13
|
+
const axios_1 = require("../../utilities/axios");
|
|
14
|
+
const metric_logger_1 = require("../../utilities/metric-logger");
|
|
15
|
+
const { output } = require('../../utilities/nx-imports');
|
|
16
|
+
class RunGroupApi {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
19
|
+
}
|
|
20
|
+
createRunGroup(branch, runGroup) {
|
|
21
|
+
var _a;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
|
|
24
|
+
try {
|
|
25
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/create-run-group', {
|
|
26
|
+
branch: branch,
|
|
27
|
+
runGroup: runGroup,
|
|
28
|
+
}));
|
|
29
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
33
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
34
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
35
|
+
output.error({
|
|
36
|
+
title: e.message,
|
|
37
|
+
});
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
completeRunGroup(runGroup) {
|
|
43
|
+
var _a;
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
|
|
46
|
+
try {
|
|
47
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
48
|
+
runGroup: runGroup,
|
|
49
|
+
}));
|
|
50
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
54
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
55
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
56
|
+
output.error({
|
|
57
|
+
title: e.message,
|
|
58
|
+
});
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.RunGroupApi = RunGroupApi;
|
|
65
|
+
//# sourceMappingURL=run-group.api.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function runCommandAndStoreInCloud(): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
|
|
4
|
+
* Recursive function that walks back up the directory
|
|
5
|
+
* tree to try and find a workspace file.
|
|
6
|
+
*
|
|
7
|
+
* @param dir Directory to start searching with
|
|
8
|
+
*/
|
|
9
|
+
export declare function findWorkspaceRoot(dir: string): WorkspaceTypeAndRoot | null;
|
|
10
|
+
/**
|
|
11
|
+
* https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
|
|
12
|
+
*/
|
|
13
|
+
export interface WorkspaceTypeAndRoot {
|
|
14
|
+
type: 'nx' | 'angular';
|
|
15
|
+
dir: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findWorkspaceRoot = exports.runCommandAndStoreInCloud = void 0;
|
|
13
|
+
const cp = require("child_process");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const environment_1 = require("../../utilities/environment");
|
|
17
|
+
const axios_1 = require("../../utilities/axios");
|
|
18
|
+
const util_1 = require("util");
|
|
19
|
+
const zlib_1 = require("zlib");
|
|
20
|
+
const output_obfuscator_1 = require("../terminal-output/output-obfuscator");
|
|
21
|
+
const print_message_1 = require("../../utilities/print-message");
|
|
22
|
+
const { output } = require('../../utilities/nx-imports');
|
|
23
|
+
const MAX_CHARACTERS_OUTPUT_CAPTURE = 200000;
|
|
24
|
+
function runCommandAndStoreInCloud() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const taskRunnerOptions = getTaskRunnerOptions();
|
|
27
|
+
const axios = (0, axios_1.createApiAxiosInstance)(taskRunnerOptions);
|
|
28
|
+
const outputObfuscator = new output_obfuscator_1.OutputObfuscator(taskRunnerOptions.maskedProperties);
|
|
29
|
+
const branch = (0, environment_1.getBranch)();
|
|
30
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
31
|
+
let userCommandAndArgs;
|
|
32
|
+
const commandStartIndex = process.argv.findIndex((arg) => arg === 'record');
|
|
33
|
+
if (commandStartIndex < process.argv.length - 1) {
|
|
34
|
+
userCommandAndArgs = process.argv.slice(commandStartIndex + 1);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log('Invalid command. Use `nx-cloud record [my command] [my arg1] [my arg...]`');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const [userCommand, ...userArgs] = userCommandAndArgs;
|
|
41
|
+
const startRecordRunRequest = {
|
|
42
|
+
branch,
|
|
43
|
+
runGroup,
|
|
44
|
+
hashes: [],
|
|
45
|
+
};
|
|
46
|
+
yield (0, axios_1.axiosMultipleTries)(() => axios.post('/nx-cloud/runs/start', startRecordRunRequest));
|
|
47
|
+
const startTime = new Date().toISOString();
|
|
48
|
+
const { statusCode, terminalOutput } = yield spawnUserCommandAndCaptureOutput(userCommand, userArgs);
|
|
49
|
+
const endTime = new Date().toISOString();
|
|
50
|
+
const endRecordOutputRunParams = {
|
|
51
|
+
statusCode,
|
|
52
|
+
terminalOutput,
|
|
53
|
+
userCommandAndArgsString: userCommandAndArgs.join(' '),
|
|
54
|
+
startTime,
|
|
55
|
+
endTime,
|
|
56
|
+
branch,
|
|
57
|
+
runGroup,
|
|
58
|
+
};
|
|
59
|
+
yield endRecordOutputRun(axios, outputObfuscator, taskRunnerOptions, endRecordOutputRunParams);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.runCommandAndStoreInCloud = runCommandAndStoreInCloud;
|
|
63
|
+
function getTaskRunnerOptions() {
|
|
64
|
+
var _a, _b, _c;
|
|
65
|
+
const workspaceRoot = findWorkspaceRoot(process.cwd());
|
|
66
|
+
if (workspaceRoot == null) {
|
|
67
|
+
throw new Error('Unable to locate task runner options.');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const taskRunnerOptions = (_c = (_b = (_a = require(`${workspaceRoot.dir}/nx.json`)) === null || _a === void 0 ? void 0 : _a.tasksRunnerOptions) === null || _b === void 0 ? void 0 : _b.default) === null || _c === void 0 ? void 0 : _c.options;
|
|
71
|
+
return taskRunnerOptions;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function splitUserCommandAndArgs(userCommandAndArgs) {
|
|
75
|
+
const userCommand = userCommandAndArgs[0];
|
|
76
|
+
let userArgs = [];
|
|
77
|
+
if (userCommandAndArgs.length > 1) {
|
|
78
|
+
userArgs = userCommandAndArgs.slice(1);
|
|
79
|
+
}
|
|
80
|
+
return { userCommand, userArgs };
|
|
81
|
+
}
|
|
82
|
+
function spawnUserCommandAndCaptureOutput(command, args) {
|
|
83
|
+
return new Promise((res, rej) => {
|
|
84
|
+
try {
|
|
85
|
+
const userCommandProcess = cp.spawn(command, args, {
|
|
86
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
87
|
+
});
|
|
88
|
+
const outLines = [];
|
|
89
|
+
userCommandProcess.stdout.on('data', (chunk) => {
|
|
90
|
+
process.stdout.write(chunk);
|
|
91
|
+
outLines.push(chunk.toString());
|
|
92
|
+
});
|
|
93
|
+
userCommandProcess.stderr.on('data', (chunk) => {
|
|
94
|
+
process.stderr.write(chunk);
|
|
95
|
+
outLines.push(chunk.toString());
|
|
96
|
+
});
|
|
97
|
+
userCommandProcess.on('exit', (exitCode, exitSignal) => {
|
|
98
|
+
const statusCode = exitCode !== null && exitCode !== void 0 ? exitCode : signalToCode(exitSignal || '');
|
|
99
|
+
const joinedOutput = outLines.join('');
|
|
100
|
+
res({
|
|
101
|
+
statusCode,
|
|
102
|
+
terminalOutput: joinedOutput,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
rej(e);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function createTaskDefinitionFromUserCommand(outputObfuscator, params) {
|
|
112
|
+
const sanitizedOutput = outputObfuscator.obfuscate(params.terminalOutput);
|
|
113
|
+
const truncatedOutput = sanitizedOutput.length > MAX_CHARACTERS_OUTPUT_CAPTURE
|
|
114
|
+
? `TRUNCATED\n\n${sanitizedOutput.slice(sanitizedOutput.length - MAX_CHARACTERS_OUTPUT_CAPTURE)}`
|
|
115
|
+
: sanitizedOutput;
|
|
116
|
+
return {
|
|
117
|
+
taskId: 'nx-cloud-tasks-runner:record-command',
|
|
118
|
+
target: 'record-command',
|
|
119
|
+
projectName: 'nx-cloud-tasks-runner',
|
|
120
|
+
hash: '',
|
|
121
|
+
startTime: params.startTime,
|
|
122
|
+
endTime: params.endTime,
|
|
123
|
+
hashDetails: {},
|
|
124
|
+
params: params.userCommandAndArgsString,
|
|
125
|
+
cacheStatus: 'n/a',
|
|
126
|
+
status: params.statusCode,
|
|
127
|
+
terminalOutput: truncatedOutput,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function endRecordOutputRun(axios, obfuscator, taskRunnerOptions, params) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const commandWithPrefix = `nx-cloud record -- ${params.userCommandAndArgsString}`;
|
|
133
|
+
const endRunReq = {
|
|
134
|
+
meta: {
|
|
135
|
+
nxCloudVersion: '0.0.0',
|
|
136
|
+
},
|
|
137
|
+
tasks: [createTaskDefinitionFromUserCommand(obfuscator, params)],
|
|
138
|
+
run: {
|
|
139
|
+
command: commandWithPrefix,
|
|
140
|
+
startTime: params.startTime,
|
|
141
|
+
endTime: params.endTime,
|
|
142
|
+
branch: params.branch,
|
|
143
|
+
scan: true,
|
|
144
|
+
runGroup: params.runGroup,
|
|
145
|
+
// only set sha if branch is set because we invoke a separate process,
|
|
146
|
+
// which adds a few millis
|
|
147
|
+
sha: params.branch ? (0, environment_1.extractGitSha)() : undefined,
|
|
148
|
+
},
|
|
149
|
+
machineInfo: (0, environment_1.getMachineInfo)(taskRunnerOptions),
|
|
150
|
+
};
|
|
151
|
+
const uncompressedBuffer = Buffer.from(JSON.stringify(endRunReq));
|
|
152
|
+
const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
|
|
153
|
+
const endRunResp = yield (0, axios_1.axiosMultipleTries)(() => axios.post('/nx-cloud/runs/end', compressedBuffer, {
|
|
154
|
+
headers: Object.assign(Object.assign({}, axios.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
|
|
155
|
+
}));
|
|
156
|
+
printRecordOutputRunEndMessage(endRunResp.data.runUrl);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function printRecordOutputRunEndMessage(runUrl) {
|
|
160
|
+
output.addVerticalSeparator();
|
|
161
|
+
output.note({ title: 'Nx Cloud: Successfully recorded command output' });
|
|
162
|
+
(0, print_message_1.printMessage)(`You can view or share your output by visiting ${runUrl}`);
|
|
163
|
+
}
|
|
164
|
+
// Everything from here down is ripped from the nx package
|
|
165
|
+
// You probably don't want to adjust this manually
|
|
166
|
+
/**
|
|
167
|
+
* https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
|
|
168
|
+
* Recursive function that walks back up the directory
|
|
169
|
+
* tree to try and find a workspace file.
|
|
170
|
+
*
|
|
171
|
+
* @param dir Directory to start searching with
|
|
172
|
+
*/
|
|
173
|
+
function findWorkspaceRoot(dir) {
|
|
174
|
+
if ((0, fs_1.existsSync)(path.join(dir, 'angular.json'))) {
|
|
175
|
+
return { type: 'angular', dir };
|
|
176
|
+
}
|
|
177
|
+
if ((0, fs_1.existsSync)(path.join(dir, 'nx.json'))) {
|
|
178
|
+
return { type: 'nx', dir };
|
|
179
|
+
}
|
|
180
|
+
if (path.dirname(dir) === dir) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
return findWorkspaceRoot(path.dirname(dir));
|
|
184
|
+
}
|
|
185
|
+
exports.findWorkspaceRoot = findWorkspaceRoot;
|
|
186
|
+
/**
|
|
187
|
+
* https://github.com/nrwl/nx/blob/master/packages/nx/src/tasks-runner/forked-process-task-runner.ts
|
|
188
|
+
*
|
|
189
|
+
* @param signal
|
|
190
|
+
*/
|
|
191
|
+
function signalToCode(signal) {
|
|
192
|
+
if (signal === 'SIGHUP')
|
|
193
|
+
return 128 + 1;
|
|
194
|
+
if (signal === 'SIGINT')
|
|
195
|
+
return 128 + 2;
|
|
196
|
+
if (signal === 'SIGTERM')
|
|
197
|
+
return 128 + 15;
|
|
198
|
+
return 128;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=record-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-output.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/commands/record-output.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,2BAAgC;AAChC,6BAA6B;AAC7B,6DAKqC;AAErC,iDAG+B;AAC/B,+BAAiC;AACjC,+BAA4B;AAE5B,4EAAwE;AACxE,iEAA6D;AAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAiBzD,MAAM,6BAA6B,GAAG,MAAO,CAAC;AAE9C,SAAsB,yBAAyB;;QAC7C,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,IAAA,8BAAsB,EAAC,iBAAiB,CAAC,CAAC;QACxD,MAAM,gBAAgB,GAAG,IAAI,oCAAgB,CAC3C,iBAAiB,CAAC,gBAAgB,CACnC,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,uBAAS,GAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;QAE/B,IAAI,kBAAkB,CAAC;QAEvB,MAAM,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;QAC5E,IAAI,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/C,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC;SAChE;aAAM;YACL,OAAO,CAAC,GAAG,CACT,2EAA2E,CAC5E,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAA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ACH,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE;QAC9C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;KACjC;IAED,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE;QACzC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;KAC5B;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAdD,8CAcC;AAUD;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,GAAG,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,GAAG,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,GAAG,EAAE,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudEnabledLifeCycle = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const { appRootPath, unparse } = require('../../../utilities/nx-imports');
|
|
8
|
+
class CloudEnabledLifeCycle {
|
|
9
|
+
constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) {
|
|
10
|
+
this.runContext = runContext;
|
|
11
|
+
this.cacheDirectory = cacheDirectory;
|
|
12
|
+
this.skipNxCache = skipNxCache;
|
|
13
|
+
this.collectTerminalOutput = collectTerminalOutput;
|
|
14
|
+
this.cacheableOperations = cacheableOperations;
|
|
15
|
+
this.outputObfuscator = outputObfuscator;
|
|
16
|
+
this.tasks = tasks;
|
|
17
|
+
}
|
|
18
|
+
scheduleTask(task) {
|
|
19
|
+
this.runContext.scheduledTasks.push(task);
|
|
20
|
+
}
|
|
21
|
+
startTask(task) {
|
|
22
|
+
const overrides = Object.assign({}, (task.overrides || {}));
|
|
23
|
+
if (task.target.configuration) {
|
|
24
|
+
overrides['configuration'] = task.target.configuration;
|
|
25
|
+
}
|
|
26
|
+
this.tasks.push({
|
|
27
|
+
taskId: task.id,
|
|
28
|
+
startTime: new Date().toISOString(),
|
|
29
|
+
target: task.target.target,
|
|
30
|
+
projectName: task.target.project,
|
|
31
|
+
hash: task.hash,
|
|
32
|
+
hashDetails: this.cleanUpHashDetails(task.hashDetails),
|
|
33
|
+
params: unparse(overrides).join(' '),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Used for older version for Nx. Remove in Dec 2022
|
|
37
|
+
endTask(task, code) {
|
|
38
|
+
let cacheStatus;
|
|
39
|
+
if (this.runContext.statuses[task.hash]) {
|
|
40
|
+
cacheStatus = this.runContext.statuses[task.hash];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (this.cacheableOperations.indexOf(task.target.target) > -1 &&
|
|
44
|
+
!this.skipNxCache) {
|
|
45
|
+
cacheStatus = 'local-cache-hit';
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
cacheStatus = 'cache-miss';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.updateStartedTask(task, code, cacheStatus);
|
|
52
|
+
}
|
|
53
|
+
endTasks(tasks) {
|
|
54
|
+
for (let t of tasks) {
|
|
55
|
+
const status = t.status === 'remote-cache'
|
|
56
|
+
? 'remote-cache-hit'
|
|
57
|
+
: t.status === 'local-cache' ||
|
|
58
|
+
t.status === 'local-cache-kept-existing'
|
|
59
|
+
? 'local-cache-hit'
|
|
60
|
+
: 'cache-miss';
|
|
61
|
+
this.updateStartedTask(t.task, t.code, status);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
endCommand() { }
|
|
65
|
+
updateStartedTask(task, code, cacheStatus) {
|
|
66
|
+
const startedTask = this.tasks.find((t) => t.taskId === task.id);
|
|
67
|
+
if (!startedTask) {
|
|
68
|
+
throw new Error(`Cannot find task ${task.id}`);
|
|
69
|
+
}
|
|
70
|
+
startedTask.endTime = new Date().toISOString();
|
|
71
|
+
startedTask.status = code;
|
|
72
|
+
startedTask.params = this.outputObfuscator.obfuscate(startedTask.params);
|
|
73
|
+
startedTask.cacheStatus = cacheStatus;
|
|
74
|
+
if (this.collectTerminalOutput) {
|
|
75
|
+
startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
getTerminalOutput(hash, cacheStatus, code) {
|
|
79
|
+
let dir;
|
|
80
|
+
if (this.cacheDirectory) {
|
|
81
|
+
if (this.cacheDirectory.startsWith('./')) {
|
|
82
|
+
dir = (0, path_1.join)(appRootPath, this.cacheDirectory);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
dir = this.cacheDirectory;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
dir = (0, path_1.join)(appRootPath, 'node_modules', '.cache', 'nx');
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const taskOutput = this.readTerminalOutputFile(dir, hash);
|
|
93
|
+
const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput);
|
|
94
|
+
const maxCharacters = cacheStatus === 'cache-miss'
|
|
95
|
+
? code === 0
|
|
96
|
+
? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK
|
|
97
|
+
: CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK
|
|
98
|
+
: CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK;
|
|
99
|
+
return taskOutputSanitized.length > maxCharacters
|
|
100
|
+
? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}`
|
|
101
|
+
: taskOutputSanitized;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
cleanUpHashDetails(hashDetails) {
|
|
108
|
+
const nodes = {};
|
|
109
|
+
Object.keys(hashDetails.nodes)
|
|
110
|
+
.filter((k) => !k.startsWith('npm:'))
|
|
111
|
+
.forEach((k) => {
|
|
112
|
+
nodes[k] = hashDetails.nodes[k];
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
nodes,
|
|
116
|
+
runtime: hashDetails.runtime,
|
|
117
|
+
implicitDeps: hashDetails.implicitDeps,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
readTerminalOutputFile(dir, hash) {
|
|
121
|
+
try {
|
|
122
|
+
return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString();
|
|
123
|
+
}
|
|
124
|
+
catch (_a) {
|
|
125
|
+
try {
|
|
126
|
+
return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString();
|
|
127
|
+
}
|
|
128
|
+
catch (_b) {
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle;
|
|
135
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000;
|
|
136
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000;
|
|
137
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 5000;
|
|
138
|
+
//# sourceMappingURL=cloud-enabled-life-cycle.js.map
|