@nrwl/nx-cloud 14.4.0 → 14.4.2-beta.2
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 +3 -3
- package/bin/nx-cloud.js.map +1 -1
- package/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.d.ts +1 -1
- package/lib/core/api/run-group.api.js +68 -1
- package/lib/core/api/run-group.api.js.map +1 -1
- package/lib/core/commands/start-ci-run.js +7 -1
- package/lib/core/commands/start-ci-run.js.map +1 -1
- package/lib/core/models/distributed-agent/tasks-api-response.model.d.ts +1 -0
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +156 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +201 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +166 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +263 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js.map +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +143 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +220 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js.map +1 -1
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
- package/lib/core/runners/distributed-execution/task-graph-creator.js +77 -1
- package/lib/utilities/create-unchanged-value-timeout.d.ts +4 -0
- package/lib/utilities/{create-no-new-messages-timeout.js → create-unchanged-value-timeout.js} +6 -7
- package/lib/utilities/create-unchanged-value-timeout.js.map +1 -0
- package/lib/utilities/environment.d.ts +1 -0
- package/lib/utilities/environment.js +5 -1
- package/lib/utilities/environment.js.map +1 -1
- package/package.json +3 -2
- package/lib/utilities/create-no-new-messages-timeout.d.ts +0 -1
- package/lib/utilities/create-no-new-messages-timeout.js.map +0 -1
package/bin/nx-cloud.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const distributed_agent_impl_1 = require("../lib/core/runners/distributed-agent/distributed-agent.impl");
|
|
5
|
-
const start_ci_run_1 = require("../lib/core/commands/start-ci-run");
|
|
6
|
-
const stop_all_agents_1 = require("../lib/core/commands/stop-all-agents");
|
|
7
4
|
const clean_up_agents_1 = require("../lib/core/commands/clean-up-agents");
|
|
8
5
|
const record_output_1 = require("../lib/core/commands/record-output");
|
|
6
|
+
const start_ci_run_1 = require("../lib/core/commands/start-ci-run");
|
|
7
|
+
const stop_all_agents_1 = require("../lib/core/commands/stop-all-agents");
|
|
8
|
+
const distributed_agent_impl_1 = require("../lib/core/runners/distributed-agent/distributed-agent.impl");
|
|
9
9
|
const command = process.argv[2];
|
|
10
10
|
if (command === 'start-agent') {
|
|
11
11
|
(0, distributed_agent_impl_1.startAgent)().catch((e) => {
|
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,
|
|
1
|
+
{"version":3,"file":"nx-cloud.js","sourceRoot":"","sources":["../../../../../libs/nx-packages/nx-cloud/bin/nx-cloud.ts"],"names":[],"mappings":";;;AAEA,0EAAqE;AACrE,sEAA+E;AAC/E,oEAA+D;AAC/D,0EAAqE;AACrE,yGAA0F;AAE1F,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,36 @@
|
|
|
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.ErrorReporterApi = void 0;
|
|
13
|
+
const axios_1 = require("../../utilities/axios");
|
|
14
|
+
const { output } = require('../../utilities/nx-imports');
|
|
15
|
+
class ErrorReporterApi {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
18
|
+
}
|
|
19
|
+
reportError(message) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/report-client-error', {
|
|
23
|
+
message,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
output.warn({
|
|
28
|
+
title: `Unable to record the following error: '${message}'`,
|
|
29
|
+
bodyLines: [e.message],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ErrorReporterApi = ErrorReporterApi;
|
|
36
|
+
//# sourceMappingURL=error-reporter.api.js.map
|
|
@@ -2,6 +2,6 @@ import { CloudTaskRunnerOptions } from '../models/cloud-task-runner-options';
|
|
|
2
2
|
export declare class RunGroupApi {
|
|
3
3
|
private apiAxiosInstance;
|
|
4
4
|
constructor(options: CloudTaskRunnerOptions);
|
|
5
|
-
createRunGroup(branch: string | null, runGroup: string): Promise<void>;
|
|
5
|
+
createRunGroup(branch: string | null, runGroup: string, stopAgentsOnFailure?: boolean, agentCount?: number, commandCount?: number): Promise<void>;
|
|
6
6
|
completeRunGroup(runGroup: string): Promise<void>;
|
|
7
7
|
}
|
|
@@ -1 +1,68 @@
|
|
|
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, stopAgentsOnFailure, agentCount, commandCount) {
|
|
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,
|
|
27
|
+
runGroup,
|
|
28
|
+
stopAgentsOnFailure,
|
|
29
|
+
agentCount,
|
|
30
|
+
commandCount,
|
|
31
|
+
}));
|
|
32
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
36
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
37
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
38
|
+
output.error({
|
|
39
|
+
title: e.message,
|
|
40
|
+
});
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
completeRunGroup(runGroup) {
|
|
46
|
+
var _a;
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
|
|
49
|
+
try {
|
|
50
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
51
|
+
runGroup: runGroup,
|
|
52
|
+
}));
|
|
53
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
57
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
58
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
59
|
+
output.error({
|
|
60
|
+
title: e.message,
|
|
61
|
+
});
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.RunGroupApi = RunGroupApi;
|
|
68
|
+
//# sourceMappingURL=run-group.api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-group.api.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/api/run-group.api.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"run-group.api.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/api/run-group.api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAG+B;AAC/B,iEAIuC;AAGvC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEzD,MAAa,WAAW;IAGtB,YAAY,OAA+B;QACzC,IAAI,CAAC,gBAAgB,GAAG,IAAA,8BAAsB,EAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAEK,cAAc,CAClB,MAAqB,EACrB,QAAgB,EAChB,mBAA6B,EAC7B,UAAmB,EACnB,YAAqB;;;YAErB,MAAM,QAAQ,GAAG,IAAA,oCAAoB,EAAC,gBAAgB,CAAC,CAAC;YACxD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,IAAA,0BAAkB,EAAC,GAAG,EAAE,CACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,uCAAuC,EAAE;oBAClE,MAAM;oBACN,QAAQ;oBACR,mBAAmB;oBACnB,UAAU;oBACV,YAAY;iBACb,CAAC,CACH,CAAC;gBACF,QAAQ,CAAC,YAAY,CAAC,IAAA,kCAAkB,EAAC,IAAI,CAAC,CAAC,CAAC;aACjD;YAAC,OAAO,CAAM,EAAE;gBACf,QAAQ,CAAC,YAAY,CACnB,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,0CAAE,QAAQ;oBACzB,CAAC,CAAC,IAAA,kCAAkB,EAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC;oBAC/C,CAAC,CAAC,yCAAyB,CAC9B,CAAC;gBAEF,MAAM,CAAC,KAAK,CAAC;oBACX,KAAK,EAAE,CAAC,CAAC,OAAO;iBACjB,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;;KACF;IAEK,gBAAgB,CAAC,QAAgB;;;YACrC,MAAM,QAAQ,GAAG,IAAA,oCAAoB,EAAC,gBAAgB,CAAC,CAAC;YAExD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,IAAA,0BAAkB,EAAC,GAAG,EAAE,CACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,yCAAyC,EAAE;oBACpE,QAAQ,EAAE,QAAQ;iBACnB,CAAC,CACH,CAAC;gBACF,QAAQ,CAAC,YAAY,CAAC,IAAA,kCAAkB,EAAC,IAAI,CAAC,CAAC,CAAC;aACjD;YAAC,OAAO,CAAM,EAAE;gBACf,QAAQ,CAAC,YAAY,CACnB,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,0CAAE,QAAQ;oBACzB,CAAC,CAAC,IAAA,kCAAkB,EAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC;oBAC/C,CAAC,CAAC,yCAAyB,CAC9B,CAAC;gBAEF,MAAM,CAAC,KAAK,CAAC;oBACX,KAAK,EAAE,CAAC,CAAC,OAAO;iBACjB,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;;KACF;CACF;AA/DD,kCA+DC"}
|
|
@@ -15,7 +15,12 @@ const environment_1 = require("../../utilities/environment");
|
|
|
15
15
|
const print_run_group_error_1 = require("../error/print-run-group-error");
|
|
16
16
|
const run_group_api_1 = require("../api/run-group.api");
|
|
17
17
|
const fs_1 = require("fs");
|
|
18
|
+
const yargsParser = require("yargs-parser");
|
|
18
19
|
const { output, workspaceRoot } = require('../../utilities/nx-imports');
|
|
20
|
+
const args = yargsParser(process.argv, {
|
|
21
|
+
boolean: ['stop-agents-on-failure'],
|
|
22
|
+
number: ['agent-count', 'command-count'],
|
|
23
|
+
});
|
|
19
24
|
function startCiRun() {
|
|
20
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
26
|
const branch = (0, environment_1.getBranch)();
|
|
@@ -31,7 +36,8 @@ function startCiRun() {
|
|
|
31
36
|
}
|
|
32
37
|
const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default.options;
|
|
33
38
|
const api = new run_group_api_1.RunGroupApi(options);
|
|
34
|
-
|
|
39
|
+
console.log(args);
|
|
40
|
+
yield api.createRunGroup(branch, runGroup, args.stopAgentsOnFailure, args.agentCount, args.commandCount);
|
|
35
41
|
});
|
|
36
42
|
}
|
|
37
43
|
exports.startCiRun = startCiRun;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-ci-run.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/commands/start-ci-run.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAyD;AACzD,6DAIqC;AACrC,0EAAoE;AACpE,wDAAmD;AACnD,2BAAkC;
|
|
1
|
+
{"version":3,"file":"start-ci-run.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/commands/start-ci-run.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAyD;AACzD,6DAIqC;AACrC,0EAAoE;AACpE,wDAAmD;AACnD,2BAAkC;AAClC,4CAA4C;AAE5C,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACxE,MAAM,IAAI,GAAQ,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE;IAC1C,OAAO,EAAE,CAAC,wBAAwB,CAAC;IACnC,MAAM,EAAE,CAAC,aAAa,EAAE,eAAe,CAAC;CACzC,CAAC,CAAC;AAEH,SAAsB,UAAU;;QAC9B,MAAM,MAAM,GAAG,IAAA,uBAAS,GAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;QAE/B,IAAI,CAAC,QAAQ,EAAE;YACb,IAAA,0CAAkB,GAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,IAAI,6BAAe,EAAE;YACnB,MAAM,CAAC,IAAI,CAAC;gBACV,KAAK,EAAE,sBAAsB,QAAQ,EAAE;aACxC,CAAC,CAAC;SACJ;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CACxB,iBAAiB,CAAC,IAAA,iBAAY,EAAC,GAAG,aAAa,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CACvE,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC;QAErC,MAAM,GAAG,GAAG,IAAI,2BAAW,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,MAAM,GAAG,CAAC,cAAc,CACtB,MAAM,EACN,QAAQ,EACR,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,YAAY,CAClB,CAAC;IACJ,CAAC;CAAA;AA3BD,gCA2BC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TaskToExecute } from './task-to-execute.model';
|
|
2
2
|
export interface TasksApiResponse {
|
|
3
3
|
completed: boolean;
|
|
4
|
+
status?: 'RUN_GROUP_COMPLETED' | 'NO_FURTHER_TASKS_TO_RUN' | 'IN_PROGRESS';
|
|
4
5
|
retryDuring: number | null;
|
|
5
6
|
executionId: string | null;
|
|
6
7
|
tasks: TaskToExecute[];
|
|
@@ -1 +1,156 @@
|
|
|
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 environment_1 = require("../../../utilities/environment");
|
|
8
|
+
const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
|
|
9
|
+
const { workspaceRoot } = require('../../../utilities/nx-imports');
|
|
10
|
+
class CloudEnabledLifeCycle {
|
|
11
|
+
constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) {
|
|
12
|
+
this.runContext = runContext;
|
|
13
|
+
this.cacheDirectory = cacheDirectory;
|
|
14
|
+
this.skipNxCache = skipNxCache;
|
|
15
|
+
this.collectTerminalOutput = collectTerminalOutput;
|
|
16
|
+
this.cacheableOperations = cacheableOperations;
|
|
17
|
+
this.outputObfuscator = outputObfuscator;
|
|
18
|
+
this.tasks = tasks;
|
|
19
|
+
}
|
|
20
|
+
scheduleTask(task) {
|
|
21
|
+
this.runContext.scheduledTasks.push(task);
|
|
22
|
+
}
|
|
23
|
+
startTask(task) {
|
|
24
|
+
this.tasks.push({
|
|
25
|
+
taskId: task.id,
|
|
26
|
+
startTime: new Date().toISOString(),
|
|
27
|
+
target: task.target.target,
|
|
28
|
+
projectName: task.target.project,
|
|
29
|
+
hash: task.hash,
|
|
30
|
+
hashDetails: this.cleanUpHashDetails(task.hashDetails),
|
|
31
|
+
params: (0, serializer_overrides_1.serializeOverrides)(task),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Used for older version for Nx. Remove in Dec 2022
|
|
35
|
+
endTask(task, code) {
|
|
36
|
+
let cacheStatus;
|
|
37
|
+
if (this.runContext.statuses[task.hash]) {
|
|
38
|
+
cacheStatus = this.runContext.statuses[task.hash];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (this.cacheableOperations.indexOf(task.target.target) > -1 &&
|
|
42
|
+
!this.skipNxCache) {
|
|
43
|
+
cacheStatus = 'local-cache-hit';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
cacheStatus = 'cache-miss';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
this.updateStartedTask(task, code, cacheStatus);
|
|
50
|
+
}
|
|
51
|
+
endTasks(tasks) {
|
|
52
|
+
for (let t of tasks) {
|
|
53
|
+
let cacheStatus;
|
|
54
|
+
const taskIsRemoteCacheHit = t.status === 'remote-cache';
|
|
55
|
+
const taskIsLocalCacheHitPreNx135 = t.status === 'cache';
|
|
56
|
+
const taskIsLocalCacheHit = t.status === 'local-cache' ||
|
|
57
|
+
t.status === 'local-cache-kept-existing' ||
|
|
58
|
+
taskIsLocalCacheHitPreNx135;
|
|
59
|
+
if (this.runContext.statuses[t.task.hash]) {
|
|
60
|
+
cacheStatus = this.runContext.statuses[t.task.hash];
|
|
61
|
+
}
|
|
62
|
+
else if (taskIsRemoteCacheHit) {
|
|
63
|
+
cacheStatus = 'remote-cache-hit';
|
|
64
|
+
}
|
|
65
|
+
else if (taskIsLocalCacheHit) {
|
|
66
|
+
cacheStatus = 'local-cache-hit';
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (this.cacheableOperations.indexOf(t.task.target.target) > -1 &&
|
|
70
|
+
!this.skipNxCache) {
|
|
71
|
+
cacheStatus = 'local-cache-hit';
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
cacheStatus = 'cache-miss';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
this.updateStartedTask(t.task, t.code, cacheStatus);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
endCommand() { }
|
|
81
|
+
updateStartedTask(task, code, cacheStatus) {
|
|
82
|
+
const startedTask = this.tasks.find((t) => t.taskId === task.id);
|
|
83
|
+
if (!startedTask) {
|
|
84
|
+
throw new Error(`Cannot find task ${task.id}`);
|
|
85
|
+
}
|
|
86
|
+
startedTask.endTime = new Date().toISOString();
|
|
87
|
+
startedTask.status = code;
|
|
88
|
+
startedTask.params = this.outputObfuscator.obfuscate(startedTask.params);
|
|
89
|
+
startedTask.cacheStatus = cacheStatus;
|
|
90
|
+
if (this.collectTerminalOutput) {
|
|
91
|
+
startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getTerminalOutput(hash, cacheStatus, code) {
|
|
95
|
+
let dir;
|
|
96
|
+
if (this.cacheDirectory) {
|
|
97
|
+
if (this.cacheDirectory.startsWith('./')) {
|
|
98
|
+
dir = (0, path_1.join)(workspaceRoot, this.cacheDirectory);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
dir = this.cacheDirectory;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
dir = (0, path_1.join)(workspaceRoot, 'node_modules', '.cache', 'nx');
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const taskOutput = this.readTerminalOutputFile(dir, hash);
|
|
109
|
+
const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput);
|
|
110
|
+
if (environment_1.NX_CLOUD_UNLIMITED_OUTPUT)
|
|
111
|
+
return taskOutputSanitized;
|
|
112
|
+
const maxCharacters = cacheStatus === 'cache-miss'
|
|
113
|
+
? code === 0
|
|
114
|
+
? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK
|
|
115
|
+
: CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK
|
|
116
|
+
: CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK;
|
|
117
|
+
return taskOutputSanitized.length > maxCharacters
|
|
118
|
+
? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}`
|
|
119
|
+
: taskOutputSanitized;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return '';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
cleanUpHashDetails(hashDetails) {
|
|
126
|
+
const nodes = {};
|
|
127
|
+
Object.keys(hashDetails.nodes)
|
|
128
|
+
.filter((k) => !k.startsWith('npm:'))
|
|
129
|
+
.forEach((k) => {
|
|
130
|
+
nodes[k] = hashDetails.nodes[k];
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
nodes,
|
|
134
|
+
runtime: hashDetails.runtime,
|
|
135
|
+
implicitDeps: hashDetails.implicitDeps,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
readTerminalOutputFile(dir, hash) {
|
|
139
|
+
try {
|
|
140
|
+
return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString();
|
|
141
|
+
}
|
|
142
|
+
catch (_a) {
|
|
143
|
+
try {
|
|
144
|
+
return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString();
|
|
145
|
+
}
|
|
146
|
+
catch (_b) {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle;
|
|
153
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000;
|
|
154
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000;
|
|
155
|
+
CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 20000;
|
|
156
|
+
//# sourceMappingURL=cloud-enabled-life-cycle.js.map
|
|
@@ -1 +1,201 @@
|
|
|
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.cloudEnabledTasksRunner = void 0;
|
|
13
|
+
const message_reporter_1 = require("../../terminal-output/message-reporter");
|
|
14
|
+
const end_of_run_message_1 = require("../../terminal-output/end-of-run-message");
|
|
15
|
+
const output_obfuscator_1 = require("../../terminal-output/output-obfuscator");
|
|
16
|
+
const cloud_enabled_life_cycle_1 = require("./cloud-enabled-life-cycle");
|
|
17
|
+
const file_storage_1 = require("../../file-storage/file-storage");
|
|
18
|
+
const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
|
|
19
|
+
const environment_1 = require("../../../utilities/environment");
|
|
20
|
+
const cloud_remote_cache_1 = require("./cloud-remote-cache");
|
|
21
|
+
const cloud_run_api_1 = require("./cloud-run.api");
|
|
22
|
+
const fs_1 = require("fs");
|
|
23
|
+
const path = require("path");
|
|
24
|
+
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
25
|
+
const error_reporter_api_1 = require("../../api/error-reporter.api");
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
const fs_extra_1 = require("fs-extra");
|
|
28
|
+
const { tasksRunner, output, Cache } = require('../../../utilities/nx-imports');
|
|
29
|
+
function createApi(errors, options, runContext) {
|
|
30
|
+
const machineInfo = (0, environment_1.getMachineInfo)(options);
|
|
31
|
+
return new cloud_run_api_1.CloudRunApi(errors, runContext, options, machineInfo);
|
|
32
|
+
}
|
|
33
|
+
function storeTaskHashes(taskExecutions, directory, distributedExecutionId) {
|
|
34
|
+
const hashes = JSON.stringify(taskExecutions.map((t) => ({
|
|
35
|
+
taskId: t.taskId,
|
|
36
|
+
hash: t.hash,
|
|
37
|
+
})));
|
|
38
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
39
|
+
output.note({
|
|
40
|
+
title: `Executed tasks with hashes: ${hashes}`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
(0, fs_1.writeFileSync)(path.join(directory, `tasks-hashes-${distributedExecutionId}`), hashes);
|
|
44
|
+
}
|
|
45
|
+
function onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const runEndTime = new Date().toISOString();
|
|
48
|
+
const branch = (0, environment_1.getBranch)();
|
|
49
|
+
const runData = {
|
|
50
|
+
command: outputObfuscator.obfuscate((0, environment_1.parseCommand)()),
|
|
51
|
+
startTime: runStartTime,
|
|
52
|
+
endTime: runEndTime,
|
|
53
|
+
distributedExecutionId: environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID,
|
|
54
|
+
branch: branch,
|
|
55
|
+
scan: true,
|
|
56
|
+
runGroup: (0, environment_1.getRunGroup)(),
|
|
57
|
+
// only set sha if branch is set because we invoke a separate process,
|
|
58
|
+
// which adds a few millis
|
|
59
|
+
sha: branch ? (0, environment_1.extractGitSha)() : undefined,
|
|
60
|
+
inner: inner,
|
|
61
|
+
};
|
|
62
|
+
if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) {
|
|
63
|
+
storeTaskHashes(taskExecutions, options.cacheDirectory || './node_modules/.cache/nx', environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID);
|
|
64
|
+
try {
|
|
65
|
+
yield remoteCache.waitForStoreRequestsToComplete();
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
output.error({
|
|
69
|
+
title: `Agent wasn't able to store artifacts`,
|
|
70
|
+
});
|
|
71
|
+
messages.printMessages();
|
|
72
|
+
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
yield api.endRun(runData, taskExecutions);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
output.error({
|
|
79
|
+
title: `Agent wasn't able to record its run`,
|
|
80
|
+
});
|
|
81
|
+
messages.printMessages();
|
|
82
|
+
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
yield Promise.all([
|
|
87
|
+
remoteCache.waitForStoreRequestsToComplete(),
|
|
88
|
+
api.endRun(runData, taskExecutions),
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
// this workaround is required because prior to Nx 13.3 we printed
|
|
92
|
+
// the end message after the runner completes, so we need to wait for the
|
|
93
|
+
// message to appear in the right place
|
|
94
|
+
if (versionOfNxBefore133) {
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
messages.printMessages();
|
|
97
|
+
if (!messages.anyErrors && !inner) {
|
|
98
|
+
endOfRunMessage.printCacheHitsMessage();
|
|
99
|
+
}
|
|
100
|
+
}, 0);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
messages.printMessages();
|
|
104
|
+
if (!messages.anyErrors && !inner) {
|
|
105
|
+
endOfRunMessage.printCacheHitsMessage();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function createLifeCycle(runContext, options, outputObfuscator, tasks) {
|
|
112
|
+
const cloudEnabledLifeCycle = new cloud_enabled_life_cycle_1.CloudEnabledLifeCycle(runContext, options.cacheDirectory, !!options.skipNxCache, options.scan === undefined ? true : options.scan, options.cacheableOperations || [], outputObfuscator, tasks);
|
|
113
|
+
try {
|
|
114
|
+
const { CompositeLifeCycle } = require('../../../utilities/nx-imports');
|
|
115
|
+
if (!CompositeLifeCycle)
|
|
116
|
+
return cloudEnabledLifeCycle;
|
|
117
|
+
return new CompositeLifeCycle([options.lifeCycle, cloudEnabledLifeCycle]);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
return cloudEnabledLifeCycle;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function fetchUrlsForKnownHashesUpfront(api, runContext, tasks, options) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
let hashes = tasks.map((t) => t.hash).filter((h) => !!h);
|
|
126
|
+
const c = new Cache(options);
|
|
127
|
+
if (!options.skipNxCache) {
|
|
128
|
+
// filter out the urls that don't have artifact stored locally
|
|
129
|
+
const promises = yield Promise.all(hashes.map((hash) => {
|
|
130
|
+
const tdCommit = (0, path_1.join)(c.cachePath, `${hash}.commit`);
|
|
131
|
+
return (0, fs_extra_1.pathExists)(tdCommit);
|
|
132
|
+
}));
|
|
133
|
+
const missingHashes = [];
|
|
134
|
+
for (let i = 0; i < promises.length; ++i) {
|
|
135
|
+
if (promises[i]) {
|
|
136
|
+
missingHashes.push(hashes[i]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
hashes = missingHashes;
|
|
140
|
+
}
|
|
141
|
+
if (hashes.length > 0) {
|
|
142
|
+
const startRunRequest = api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, hashes);
|
|
143
|
+
for (const hash of hashes) {
|
|
144
|
+
runContext.requests[hash] = startRunRequest;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function cloudEnabledTasksRunner(tasks, options, context, inner = false) {
|
|
150
|
+
const runContext = {
|
|
151
|
+
statuses: {},
|
|
152
|
+
scheduledTasks: [],
|
|
153
|
+
requests: {},
|
|
154
|
+
allTasks: tasks,
|
|
155
|
+
};
|
|
156
|
+
const versionOfNxBefore133 = options.lifeCycle === undefined;
|
|
157
|
+
const taskExecutions = [];
|
|
158
|
+
const messages = new message_reporter_1.MessageReporter(options);
|
|
159
|
+
const api = createApi(messages, options, runContext);
|
|
160
|
+
const endOfRunMessage = new end_of_run_message_1.EndOfRunMessage(runContext, taskExecutions);
|
|
161
|
+
const outputObfuscator = new output_obfuscator_1.OutputObfuscator(options.maskedProperties);
|
|
162
|
+
const runStartTime = new Date().toISOString();
|
|
163
|
+
const lifeCycle = createLifeCycle(runContext, options, outputObfuscator, taskExecutions);
|
|
164
|
+
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
|
|
165
|
+
const errorApi = new error_reporter_api_1.ErrorReporterApi(options);
|
|
166
|
+
const fileStorage = new file_storage_1.FileStorage(encryption, errorApi, false);
|
|
167
|
+
const remoteCache = new cloud_remote_cache_1.CloudRemoteCache(messages, api, runContext, fileStorage);
|
|
168
|
+
// we don't await for it cause this step is optional
|
|
169
|
+
fetchUrlsForKnownHashesUpfront(api, runContext, tasks, options);
|
|
170
|
+
// have to reset it so we don't capture inner tasks
|
|
171
|
+
delete process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID;
|
|
172
|
+
const res = tasksRunner(tasks, Object.assign(Object.assign({}, options), { remoteCache, lifeCycle }), context);
|
|
173
|
+
// observable -> legacy
|
|
174
|
+
if (res.subscribe) {
|
|
175
|
+
const { Subject } = require('rxjs/internal/Subject');
|
|
176
|
+
const wrappedRes = new Subject();
|
|
177
|
+
res.subscribe({
|
|
178
|
+
next: (value) => wrappedRes.next(value),
|
|
179
|
+
error: (err) => wrappedRes.error(err),
|
|
180
|
+
complete: () => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
|
|
182
|
+
wrappedRes.complete();
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
return wrappedRes;
|
|
186
|
+
// promise
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
return res
|
|
190
|
+
.then((r) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
|
|
192
|
+
return r;
|
|
193
|
+
}))
|
|
194
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
|
|
196
|
+
throw e;
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.cloudEnabledTasksRunner = cloudEnabledTasksRunner;
|
|
201
|
+
//# sourceMappingURL=cloud-enabled.runner.js.map
|