forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-local-publication.mjs
More file actions
109 lines (99 loc) · 3 KB
/
Copy pathvalidate-local-publication.mjs
File metadata and controls
109 lines (99 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import {
validateNativeClassifierJar,
validatePlaceholderJar,
} from "./validate-native-artifact.mjs";
export function validateLocalPublication({
artifactId,
repositoryPath,
repoRoot,
requireSignatures,
version,
}) {
const artifactDirectory = path.join(
repositoryPath,
"com",
"github",
artifactId,
version,
);
const requiredArtifacts = [
`${artifactId}-${version}.jar`,
`${artifactId}-${version}.pom`,
`${artifactId}-${version}-sources.jar`,
`${artifactId}-${version}-javadoc.jar`,
`${artifactId}-${version}-linux-x64.jar`,
`${artifactId}-${version}-win32-x64.jar`,
`${artifactId}-${version}-darwin-arm64.jar`,
];
const files = new Set(fs.readdirSync(artifactDirectory));
for (const artifact of requiredArtifacts) {
if (!files.has(artifact)) {
throw new Error(`Local publication is missing ${artifact}`);
}
if (requireSignatures && !files.has(`${artifact}.asc`)) {
throw new Error(
`Local release publication is missing signature ${artifact}.asc`,
);
}
}
const publishedJars = [...files]
.filter((file) => file.endsWith(".jar"))
.sort();
const expectedJars = requiredArtifacts
.filter((file) => file.endsWith(".jar"))
.sort();
if (publishedJars.join("\n") !== expectedJars.join("\n")) {
throw new Error(
`Local publication contains unexpected JARs:\n${publishedJars.join("\n")}`,
);
}
validatePlaceholderJar(
path.join(artifactDirectory, `${artifactId}-${version}.jar`),
);
for (const classifier of ["linux-x64", "win32-x64", "darwin-arm64"]) {
const filename = `${artifactId}-${version}-${classifier}.jar`;
validateNativeClassifierJar({
classifier,
jarPath: path.join(artifactDirectory, filename),
expectedFilename: filename,
repoRoot,
});
}
return artifactDirectory;
}
function main() {
const [repositoryPath, artifactId, version, repoRoot, signatures] =
process.argv.slice(2);
if (!repositoryPath || !artifactId || !version || !repoRoot) {
console.error(
"Usage: node validate-local-publication.mjs <repositoryPath> <artifactId> <version> <repoRoot> [--signatures]",
);
process.exitCode = 1;
return;
}
try {
const artifactDirectory = validateLocalPublication({
artifactId,
repositoryPath,
repoRoot,
requireSignatures: signatures === "--signatures",
version,
});
console.log(`Validated local Maven publication: ${artifactDirectory}`);
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}
if (
process.argv[1] &&
import.meta.url === pathToFileURL(process.argv[1]).href
) {
main();
}