@nx/gradle 22.6.3 → 22.6.5
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/batch-runner/build/libs/gradle-batch-runner-all.jar +0 -0
- package/batch-runner/build/libs/gradle-batch-runner.jar +0 -0
- package/batch-runner/build/nx/gradle-batch-runner.json +1 -1
- package/package.json +5 -4
- package/project-graph/build/nx/gradle-project-graph.json +1 -1
- package/src/executors/gradle/gradle-batch.impl.js +31 -12
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.d.ts.map +1 -1
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.js +19 -8
- package/src/plugin/utils/get-project-graph-lines.d.ts +5 -0
- package/src/plugin/utils/get-project-graph-lines.d.ts.map +1 -1
- package/src/plugin/utils/get-project-graph-lines.js +24 -3
- package/src/utils/exec-gradle.d.ts.map +1 -1
- package/src/utils/exec-gradle.js +16 -3
- package/project-graph/publish-maven.d.ts +0 -2
- package/project-graph/publish-maven.d.ts.map +0 -1
- package/project-graph/publish-maven.js +0 -103
|
@@ -4,7 +4,6 @@ exports.batchRunnerPath = void 0;
|
|
|
4
4
|
exports.default = gradleBatch;
|
|
5
5
|
exports.getGradlewTasksToRun = getGradlewTasksToRun;
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
|
8
7
|
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
9
8
|
const path_1 = require("path");
|
|
10
9
|
const child_process_1 = require("child_process");
|
|
@@ -111,20 +110,40 @@ function getGradlewTasksToRun(taskIds, taskGraph, inputs, nodes) {
|
|
|
111
110
|
}
|
|
112
111
|
async function runTasksInBatch(gradlewTasksToRun, excludeTasks, excludeTestTasks, args, root) {
|
|
113
112
|
const gradlewBatchStart = performance.mark(`gradlew-batch:start`);
|
|
114
|
-
const debugOptions =
|
|
115
|
-
const
|
|
116
|
-
.
|
|
117
|
-
|
|
113
|
+
const debugOptions = (process.env.NX_GRADLE_BATCH_DEBUG ?? '').trim();
|
|
114
|
+
const spawnArgs = [
|
|
115
|
+
...(debugOptions ? debugOptions.split(/\s+/) : []),
|
|
116
|
+
'-jar',
|
|
117
|
+
exports.batchRunnerPath,
|
|
118
|
+
`--tasks=${JSON.stringify(gradlewTasksToRun)}`,
|
|
119
|
+
`--workspaceRoot=${root}`,
|
|
120
|
+
`--args=${args.join(' ').replaceAll("'", '"')}`,
|
|
121
|
+
`--excludeTasks=${Array.from(excludeTasks).join(',')}`,
|
|
122
|
+
`--excludeTestTasks=${Array.from(excludeTestTasks).join(',')}`,
|
|
123
|
+
...(process.env.NX_VERBOSE_LOGGING === 'true' ? [] : ['--quiet']),
|
|
124
|
+
];
|
|
118
125
|
// Use 'inherit' for stderr so Gradle output (tee'd to System.err
|
|
119
126
|
// by TeeOutputStream) flows to the terminal in real-time.
|
|
120
127
|
// stdout is piped to capture the JSON batch results.
|
|
121
|
-
const batchResults = (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
const batchResults = await new Promise((resolve, reject) => {
|
|
129
|
+
const cp = (0, child_process_1.spawn)('java', spawnArgs, {
|
|
130
|
+
cwd: devkit_1.workspaceRoot,
|
|
131
|
+
windowsHide: true,
|
|
132
|
+
env: process.env,
|
|
133
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
134
|
+
});
|
|
135
|
+
const chunks = [];
|
|
136
|
+
cp.stdout.on('data', (chunk) => chunks.push(chunk));
|
|
137
|
+
cp.on('error', reject);
|
|
138
|
+
cp.on('close', (code) => {
|
|
139
|
+
if (code !== 0) {
|
|
140
|
+
reject(new Error(`Gradle batch runner exited with code ${code}`));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
resolve(Buffer.concat(chunks).toString());
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
128
147
|
const gradlewBatchEnd = performance.mark(`gradlew-batch:end`);
|
|
129
148
|
performance.measure(`gradlew-batch`, gradlewBatchStart.name, gradlewBatchEnd.name);
|
|
130
149
|
const gradlewBatchResults = JSON.parse(batchResults);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-project-graph-from-gradle-plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/plugin/utils/get-project-graph-from-gradle-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,oBAAoB,EACpB,wBAAwB,EAExB,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,mBAAmB,EAAoB,MAAM,yBAAyB,CAAC;AAIhF,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE;QACL,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;KAClD,CAAC;IACF,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACzD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAiBD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,QAgBb;
|
|
1
|
+
{"version":3,"file":"get-project-graph-from-gradle-plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/plugin/utils/get-project-graph-from-gradle-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,oBAAoB,EACpB,wBAAwB,EAExB,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,mBAAmB,EAAoB,MAAM,yBAAyB,CAAC;AAIhF,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE;QACL,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;KAClD,CAAC;IACF,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACzD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAiBD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,QAgBb;AAOD,wBAAgB,4BAA4B,IAAI,kBAAkB,CAejE;AAED,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAG/C;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAyEf;AAED,wBAAgB,qBAAqB,CACnC,iBAAiB,EAAE,MAAM,EAAE,GAC1B,kBAAkB,CAkDpB"}
|
|
@@ -75,14 +75,25 @@ async function populateProjectGraph(workspaceRoot, gradlewFiles, options) {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
const gradleProjectGraphReportStart = performance.mark('gradleProjectGraphReport:start');
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
let projectGraphLines;
|
|
79
|
+
try {
|
|
80
|
+
projectGraphLines = await gradlewFiles.reduce(async (projectGraphLines, gradlewFile) => {
|
|
81
|
+
const getNxProjectGraphLinesStart = performance.mark(`${gradlewFile}GetNxProjectGraphLines:start`);
|
|
82
|
+
const allLines = await projectGraphLines;
|
|
83
|
+
const currentLines = await (0, get_project_graph_lines_1.getNxProjectGraphLines)(gradlewFile, gradleConfigHash, normalizedOptions);
|
|
84
|
+
const getNxProjectGraphLinesEnd = performance.mark(`${gradlewFile}GetNxProjectGraphLines:end`);
|
|
85
|
+
performance.measure(`${gradlewFile}GetNxProjectGraphLines`, getNxProjectGraphLinesStart.name, getNxProjectGraphLinesEnd.name);
|
|
86
|
+
return [...allLines, ...currentLines];
|
|
87
|
+
}, Promise.resolve([]));
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
if (e instanceof Error &&
|
|
91
|
+
e.message === 'Gradle project graph generation was cancelled') {
|
|
92
|
+
// Cancelled by a newer populateProjectGraph call — silently return
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
86
97
|
const gradleProjectGraphReportEnd = performance.mark('gradleProjectGraphReport:end');
|
|
87
98
|
performance.measure('gradleProjectGraphReport', gradleProjectGraphReportStart.name, gradleProjectGraphReportEnd.name);
|
|
88
99
|
projectGraphReportCache = processNxProjectGraph(projectGraphLines);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { GradlePluginOptions } from './gradle-plugin-options';
|
|
2
|
+
/**
|
|
3
|
+
* Cancel any in-flight Gradle project graph process.
|
|
4
|
+
* Safe to call even if nothing is running.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cancelPendingProjectGraphRequest(): void;
|
|
2
7
|
export declare function getGraphTimeoutMs(): number;
|
|
3
8
|
export declare function getNxProjectGraphLines(gradlewFile: string, gradleConfigHash: string, gradlePluginOptions: GradlePluginOptions): Promise<string[]>;
|
|
4
9
|
//# sourceMappingURL=get-project-graph-lines.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-project-graph-lines.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/plugin/utils/get-project-graph-lines.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-project-graph-lines.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/plugin/utils/get-project-graph-lines.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;;GAGG;AACH,wBAAgB,gCAAgC,IAAI,IAAI,CAKvD;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAS1C;AAED,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,mBAAmB,EAAE,mBAAmB,GACvC,OAAO,CAAC,MAAM,EAAE,CAAC,CA6GnB"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cancelPendingProjectGraphRequest = cancelPendingProjectGraphRequest;
|
|
3
4
|
exports.getGraphTimeoutMs = getGraphTimeoutMs;
|
|
4
5
|
exports.getNxProjectGraphLines = getNxProjectGraphLines;
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
6
8
|
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
7
|
-
const DEFAULT_GRAPH_TIMEOUT_SECONDS =
|
|
9
|
+
const DEFAULT_GRAPH_TIMEOUT_SECONDS = (0, devkit_internals_1.isCI)() ? 600 : 120;
|
|
10
|
+
let currentAbortController;
|
|
11
|
+
/**
|
|
12
|
+
* Cancel any in-flight Gradle project graph process.
|
|
13
|
+
* Safe to call even if nothing is running.
|
|
14
|
+
*/
|
|
15
|
+
function cancelPendingProjectGraphRequest() {
|
|
16
|
+
if (currentAbortController) {
|
|
17
|
+
currentAbortController.abort('cancelled');
|
|
18
|
+
currentAbortController = undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
8
21
|
function getGraphTimeoutMs() {
|
|
9
22
|
const envTimeout = process.env.NX_GRADLE_PROJECT_GRAPH_TIMEOUT;
|
|
10
23
|
if (envTimeout) {
|
|
@@ -20,7 +33,11 @@ async function getNxProjectGraphLines(gradlewFile, gradleConfigHash, gradlePlugi
|
|
|
20
33
|
const gradlePluginOptionsArgs = Object.entries(gradlePluginOptions ?? {})?.map(([key, value]) => `-P${key}=${value}`) ?? [];
|
|
21
34
|
const timeoutMs = getGraphTimeoutMs();
|
|
22
35
|
const timeoutSeconds = timeoutMs / 1000;
|
|
36
|
+
// Cancel any in-flight Gradle process from a previous call, then create a fresh controller.
|
|
37
|
+
cancelPendingProjectGraphRequest();
|
|
23
38
|
const controller = new AbortController();
|
|
39
|
+
currentAbortController = controller;
|
|
40
|
+
const signal = controller.signal;
|
|
24
41
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
25
42
|
try {
|
|
26
43
|
nxProjectGraphBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
@@ -34,10 +51,14 @@ async function getNxProjectGraphLines(gradlewFile, gradleConfigHash, gradlePlugi
|
|
|
34
51
|
...gradlePluginOptionsArgs,
|
|
35
52
|
`-PworkspaceRoot=${devkit_1.workspaceRoot}`,
|
|
36
53
|
process.env.NX_GRADLE_VERBOSE_LOGGING ? '--info' : '',
|
|
37
|
-
], { signal
|
|
54
|
+
], { signal });
|
|
38
55
|
}
|
|
39
56
|
catch (e) {
|
|
40
|
-
|
|
57
|
+
// Cancelled by a newer populateProjectGraph call — let the caller handle it
|
|
58
|
+
if (signal.reason === 'cancelled') {
|
|
59
|
+
throw new Error('Gradle project graph generation was cancelled');
|
|
60
|
+
}
|
|
61
|
+
if (signal.aborted) {
|
|
41
62
|
throw new devkit_1.AggregateCreateNodesError([
|
|
42
63
|
[
|
|
43
64
|
gradlewFile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec-gradle.d.ts","sourceRoot":"","sources":["../../../../../packages/gradle/src/utils/exec-gradle.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAY,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"exec-gradle.d.ts","sourceRoot":"","sources":["../../../../../packages/gradle/src/utils/exec-gradle.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAY,MAAM,oBAAoB,CAAC;AAQ/D,eAAO,MAAM,aAAa,QAEb,CAAC;AAEd,eAAO,MAAM,gBAAgB,QAErB,CAAC;AAET;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,WAAW,GAAE,eAAoB,GAChC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,wBAAgB,4CAA4C,CAC1D,MAAM,EAAE,mBAAmB,GAC1B,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,yBAAyB,CAAC,EAAE,MAAM,GACjC,MAAM,CASR;AAED,wBAAgB,iCAAiC,CAC/C,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,iBAAiB,CAAC,EAAE,MAAM,UAoC3B;AAED,wBAAgB,yCAAyC,CACvD,+BAA+B,EAAE,MAAM,EACvC,aAAa,EAAE,MAAM,UAqCtB"}
|
package/src/utils/exec-gradle.js
CHANGED
|
@@ -13,6 +13,7 @@ const node_fs_1 = require("node:fs");
|
|
|
13
13
|
const node_path_1 = require("node:path");
|
|
14
14
|
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
|
15
15
|
const exit_codes_1 = require("nx/src/utils/exit-codes");
|
|
16
|
+
const treeKill = require("tree-kill");
|
|
16
17
|
exports.fileSeparator = process.platform.startsWith('win')
|
|
17
18
|
? 'file:///'
|
|
18
19
|
: 'file://';
|
|
@@ -34,6 +35,9 @@ function getGradleExecFile() {
|
|
|
34
35
|
* @returns promise with the stdout buffer
|
|
35
36
|
*/
|
|
36
37
|
function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
38
|
+
// Extract signal so we can handle cancellation with tree-kill
|
|
39
|
+
// instead of Node's default which only kills the immediate child.
|
|
40
|
+
const { signal, ...restOptions } = execOptions;
|
|
37
41
|
return new Promise((res, rej) => {
|
|
38
42
|
const cp = (0, node_child_process_1.execFile)(gradleBinaryPath, args, {
|
|
39
43
|
cwd: (0, node_path_1.dirname)(gradleBinaryPath),
|
|
@@ -41,8 +45,16 @@ function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
|
41
45
|
windowsHide: true,
|
|
42
46
|
env: process.env,
|
|
43
47
|
maxBuffer: run_commands_impl_1.LARGE_BUFFER,
|
|
44
|
-
...
|
|
48
|
+
...restOptions,
|
|
45
49
|
}, undefined);
|
|
50
|
+
// Use tree-kill on abort to kill the entire process tree
|
|
51
|
+
// (cmd.exe → gradlew.bat → java.exe), not just the shell.
|
|
52
|
+
const onAbort = () => {
|
|
53
|
+
if (cp.pid) {
|
|
54
|
+
treeKill(cp.pid);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
46
58
|
let stdout = Buffer.from('');
|
|
47
59
|
cp.stdout?.on('data', (data) => {
|
|
48
60
|
stdout += data;
|
|
@@ -50,9 +62,10 @@ function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
|
50
62
|
cp.stderr?.on('data', (data) => {
|
|
51
63
|
stdout += data;
|
|
52
64
|
});
|
|
53
|
-
cp.on('exit', (code,
|
|
65
|
+
cp.on('exit', (code, s) => {
|
|
66
|
+
signal?.removeEventListener('abort', onAbort);
|
|
54
67
|
if (code === null)
|
|
55
|
-
code = (0, exit_codes_1.signalToCode)(
|
|
68
|
+
code = (0, exit_codes_1.signalToCode)(s);
|
|
56
69
|
if (code === 0) {
|
|
57
70
|
res(stdout);
|
|
58
71
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publish-maven.d.ts","sourceRoot":"","sources":["../../../../packages/gradle/project-graph/publish-maven.ts"],"names":[],"mappings":""}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const axios_1 = require("axios");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const FormData = require("form-data");
|
|
6
|
-
function parseArgs() {
|
|
7
|
-
const args = process.argv.slice(2);
|
|
8
|
-
const result = {};
|
|
9
|
-
args.forEach((arg) => {
|
|
10
|
-
const [key, value] = arg.replace(/^--/, '').split('=');
|
|
11
|
-
result[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
async function publishToMavenApi(username, password, deploymentZipPath = 'deployment.zip') {
|
|
16
|
-
const token = Buffer.from(`${username}:${password}`).toString('base64');
|
|
17
|
-
console.log(`📦 Publishing to Maven Central...`);
|
|
18
|
-
const url = 'https://central.sonatype.com/api/v1/publisher/upload';
|
|
19
|
-
const form = new FormData();
|
|
20
|
-
form.append('bundle', fs.createReadStream(deploymentZipPath));
|
|
21
|
-
let uploadId;
|
|
22
|
-
try {
|
|
23
|
-
const response = await axios_1.default.post(url, form, {
|
|
24
|
-
headers: {
|
|
25
|
-
Authorization: `Basic ${token}`,
|
|
26
|
-
...form.getHeaders(),
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
uploadId = response.data.toString().trim();
|
|
30
|
-
console.log(`✅ Upload ID: ${uploadId}`);
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
console.error('🚫 Upload failed:', err.response?.data || err.message);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
let currentStatus = await getUploadStatus(uploadId, token);
|
|
37
|
-
if (['PENDING', 'VALIDATING', 'PUBLISHING'].includes(currentStatus)) {
|
|
38
|
-
currentStatus = await retryUntilValidatedOrPublished(currentStatus, uploadId, token);
|
|
39
|
-
}
|
|
40
|
-
if (!['VALIDATED', 'PUBLISHED'].includes(currentStatus)) {
|
|
41
|
-
console.error(`🚫 Upload failed with final status: ${currentStatus}`);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
console.log(`📦 Upload is ${currentStatus}, proceeding to deploy...`);
|
|
45
|
-
if (currentStatus === 'PUBLISHED') {
|
|
46
|
-
console.log('✅ Already published, skipping deployment.');
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const deployUrl = `https://central.sonatype.com/api/v1/publisher/deployment/${uploadId}`;
|
|
50
|
-
try {
|
|
51
|
-
const deployRes = await axios_1.default.post(deployUrl, null, {
|
|
52
|
-
headers: { Authorization: `Basic ${token}` },
|
|
53
|
-
});
|
|
54
|
-
console.log(`🚀 Deployment response: ${deployRes.data}`);
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
console.error('🚫 Deployment failed:', err.response?.data || err.message);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function getUploadStatus(uploadId, token) {
|
|
62
|
-
const url = `https://central.sonatype.com/api/v1/publisher/status?id=${uploadId}`;
|
|
63
|
-
try {
|
|
64
|
-
const response = await axios_1.default.post(url, null, {
|
|
65
|
-
headers: { Authorization: `Basic ${token}` },
|
|
66
|
-
});
|
|
67
|
-
const state = response.data.deploymentState;
|
|
68
|
-
console.log(`📡 Current deployment state: ${state}`);
|
|
69
|
-
return state;
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
console.error('🚫 Failed to get status:', err.response?.data || err.message);
|
|
73
|
-
return 'FAILED';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async function retryUntilValidatedOrPublished(currentStatus, uploadId, token, retries = 10, delay = 10_000) {
|
|
77
|
-
for (let i = 0; i < retries; i++) {
|
|
78
|
-
console.log(`🔁 Checking status (attempt ${i + 1}/${retries})...`);
|
|
79
|
-
await sleep(delay);
|
|
80
|
-
currentStatus = await getUploadStatus(uploadId, token);
|
|
81
|
-
if (['VALIDATED', 'PUBLISHED', 'FAILED'].includes(currentStatus))
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
return currentStatus;
|
|
85
|
-
}
|
|
86
|
-
function sleep(ms) {
|
|
87
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
88
|
-
}
|
|
89
|
-
// Entry
|
|
90
|
-
(async function main() {
|
|
91
|
-
let { username, password, deploymentZipPath } = parseArgs();
|
|
92
|
-
username = username || process.env.MAVEN_USERNAME;
|
|
93
|
-
password = password || process.env.MAVEN_PASSWORD;
|
|
94
|
-
if (!username || !password) {
|
|
95
|
-
console.error('❌ Missing MAVEN_USERNAME or MAVEN_PASSWORD');
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
if (!deploymentZipPath) {
|
|
99
|
-
console.error('❌ Missing required --deploymentZipPath argument');
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
await publishToMavenApi(username, password, deploymentZipPath);
|
|
103
|
-
})();
|