@tahminator/pipeline 1.0.76-beta.023dc7b4 → 1.0.76-beta.0f9c2cb9
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/README.md +13 -10
- package/dist/internal/create-tag/index.js +10 -13
- package/dist/internal/upload-npm/beta/index.js +10 -12
- package/dist/protobuf/backend/artifact-keeper.d.ts +25 -0
- package/dist/protobuf/backend/artifact-keeper.js +234 -0
- package/dist/protobuf/backend/index.d.ts +1 -0
- package/dist/protobuf/backend/index.js +1 -0
- package/dist/protobuf/client.d.ts +1 -6
- package/dist/protobuf/client.js +14 -42
- package/dist/protobuf/types.d.ts +34 -25
- package/dist/protobuf/types.js +4 -0
- package/dist/utils/cmd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,10 @@ import {
|
|
|
38
38
|
EnvClient,
|
|
39
39
|
GitHubClient,
|
|
40
40
|
NPMClient,
|
|
41
|
+
ProtobufCompilerBackend,
|
|
41
42
|
ProtobufCompilerClient,
|
|
43
|
+
ProtobufSourceLanguage,
|
|
44
|
+
ProtobufTargetLanguage,
|
|
42
45
|
PulumiClient,
|
|
43
46
|
SonarScannerClient,
|
|
44
47
|
Utils,
|
|
@@ -182,24 +185,24 @@ await client.promoteDockerImage({
|
|
|
182
185
|
|
|
183
186
|
### `ProtobufCompilerClient`
|
|
184
187
|
|
|
185
|
-
Generate protobuf clients with the [Buf CLI](https://buf.build/docs/installation/) and its remote plugins
|
|
188
|
+
Generate protobuf clients with the [Buf CLI](https://buf.build/docs/installation/) and its remote plugins. Java and Rust targets can be published to Artifact Keeper with Maven, Gradle, or Cargo. The client installs Buf globally with npm when necessary.
|
|
186
189
|
|
|
187
190
|
```ts
|
|
188
|
-
const
|
|
189
|
-
appId: process.env.GH_APP_ID!,
|
|
190
|
-
privateKey: await Utils.decodeBase64EncodedString(
|
|
191
|
-
process.env.GH_PRIVATE_KEY_B64!,
|
|
192
|
-
),
|
|
193
|
-
installationId: process.env.GH_INSTALLATION_ID!,
|
|
194
|
-
});
|
|
195
|
-
const protobuf = new ProtobufCompilerClient(gh);
|
|
191
|
+
const protobuf = new ProtobufCompilerClient();
|
|
196
192
|
|
|
197
193
|
await protobuf.compile({
|
|
194
|
+
backend: {
|
|
195
|
+
type: ProtobufCompilerBackend.ARTIFACT_KEEPER,
|
|
196
|
+
token: process.env.ARTIFACT_KEEPER_TOKEN!,
|
|
197
|
+
username: process.env.ARTIFACT_KEEPER_USERNAME!,
|
|
198
|
+
},
|
|
198
199
|
sourceLanguage: ProtobufSourceLanguage.RUST,
|
|
199
200
|
bufToken: process.env.BUF_TOKEN,
|
|
200
201
|
targetLanguages: {
|
|
201
202
|
[ProtobufTargetLanguage.JAVA]: {
|
|
202
|
-
|
|
203
|
+
artifactId: "hello-world-grpc-service",
|
|
204
|
+
groupId: "org.my-org",
|
|
205
|
+
version: "1.0.0",
|
|
203
206
|
},
|
|
204
207
|
},
|
|
205
208
|
protoFilesLocation: "./proto",
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { EnvClient, EnvClientStrategy } from "../../env";
|
|
2
1
|
import { GitHubClient } from "../../gh";
|
|
3
|
-
import { Utils } from "../../utils";
|
|
4
2
|
import { VersioningClient, VersionUpdatingStrategy } from "../../versioning";
|
|
5
3
|
async function main() {
|
|
6
|
-
const
|
|
7
|
-
const { githubAppAppId, githubAppInstallationId, githubAppPrivateKeyB64 } = parseCiEnv(await envClient.readFromEnv(".env.ci"));
|
|
4
|
+
const { githubAppAppId, githubAppInstallationId, githubAppPrivateKey } = parseCiEnv(process.env);
|
|
8
5
|
const ghClient = await GitHubClient.createWithGithubAppToken({
|
|
9
6
|
appId: githubAppAppId,
|
|
10
7
|
installationId: githubAppInstallationId,
|
|
11
|
-
privateKey:
|
|
8
|
+
privateKey: githubAppPrivateKey,
|
|
12
9
|
});
|
|
13
10
|
const versioningClient = new VersioningClient(ghClient, VersionUpdatingStrategy.JSTS);
|
|
14
11
|
const rootPkgJson = await Bun.file("./package.json").json();
|
|
@@ -25,27 +22,27 @@ async function main() {
|
|
|
25
22
|
}
|
|
26
23
|
function parseCiEnv(ciEnv) {
|
|
27
24
|
const githubAppAppId = (() => {
|
|
28
|
-
const v = ciEnv["
|
|
25
|
+
const v = ciEnv["_GITHUB_APP_APP_ID"];
|
|
29
26
|
if (!v) {
|
|
30
|
-
throw new Error("Missing
|
|
27
|
+
throw new Error("Missing _GITHUB_APP_APP_ID from env");
|
|
31
28
|
}
|
|
32
29
|
return v;
|
|
33
30
|
})();
|
|
34
31
|
const githubAppInstallationId = (() => {
|
|
35
|
-
const v = ciEnv["
|
|
32
|
+
const v = ciEnv["_GITHUB_APP_INSTALLATION_ID"];
|
|
36
33
|
if (!v) {
|
|
37
|
-
throw new Error("Missing
|
|
34
|
+
throw new Error("Missing _GITHUB_APP_INSTALLATION_ID from env");
|
|
38
35
|
}
|
|
39
36
|
return v;
|
|
40
37
|
})();
|
|
41
|
-
const
|
|
42
|
-
const v = ciEnv["
|
|
38
|
+
const githubAppPrivateKey = (() => {
|
|
39
|
+
const v = ciEnv["_GITHUB_APP_PEM_CONTENT"];
|
|
43
40
|
if (!v) {
|
|
44
|
-
throw new Error("Missing
|
|
41
|
+
throw new Error("Missing _GITHUB_APP_PEM_CONTENT from env");
|
|
45
42
|
}
|
|
46
43
|
return v;
|
|
47
44
|
})();
|
|
48
|
-
return { githubAppAppId, githubAppInstallationId,
|
|
45
|
+
return { githubAppAppId, githubAppInstallationId, githubAppPrivateKey };
|
|
49
46
|
}
|
|
50
47
|
main()
|
|
51
48
|
.then(() => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import yargs from "yargs";
|
|
2
2
|
import { hideBin } from "yargs/helpers";
|
|
3
|
-
import { EnvClient, EnvClientStrategy } from "../../../env";
|
|
4
3
|
import { GitHubClient } from "../../../gh";
|
|
5
4
|
import { NPMClient } from "../../../npm";
|
|
6
5
|
import { Utils } from "../../../utils";
|
|
@@ -18,12 +17,11 @@ const { sha, prId } = await yargs(hideBin(process.argv))
|
|
|
18
17
|
.strict()
|
|
19
18
|
.parse();
|
|
20
19
|
async function main() {
|
|
21
|
-
const
|
|
22
|
-
const { githubAppAppId, githubAppInstallationId, githubAppPrivateKeyB64 } = parseCiEnv(await envClient.readFromEnv(".env.ci"));
|
|
20
|
+
const { githubAppAppId, githubAppInstallationId, githubAppPrivateKey } = parseCiEnv(process.env);
|
|
23
21
|
const ghClient = await GitHubClient.createWithGithubAppToken({
|
|
24
22
|
appId: githubAppAppId,
|
|
25
23
|
installationId: githubAppInstallationId,
|
|
26
|
-
privateKey:
|
|
24
|
+
privateKey: githubAppPrivateKey,
|
|
27
25
|
});
|
|
28
26
|
const npmClient = await NPMClient.create();
|
|
29
27
|
const versioningClient = new VersioningClient(ghClient, VersionUpdatingStrategy.JSTS);
|
|
@@ -55,27 +53,27 @@ async function getShortSha(sha) {
|
|
|
55
53
|
}
|
|
56
54
|
function parseCiEnv(ciEnv) {
|
|
57
55
|
const githubAppAppId = (() => {
|
|
58
|
-
const v = ciEnv["
|
|
56
|
+
const v = ciEnv["_GITHUB_APP_APP_ID"];
|
|
59
57
|
if (!v) {
|
|
60
|
-
throw new Error("Missing
|
|
58
|
+
throw new Error("Missing _GITHUB_APP_APP_ID from env");
|
|
61
59
|
}
|
|
62
60
|
return v;
|
|
63
61
|
})();
|
|
64
62
|
const githubAppInstallationId = (() => {
|
|
65
|
-
const v = ciEnv["
|
|
63
|
+
const v = ciEnv["_GITHUB_APP_INSTALLATION_ID"];
|
|
66
64
|
if (!v) {
|
|
67
|
-
throw new Error("Missing
|
|
65
|
+
throw new Error("Missing _GITHUB_APP_INSTALLATION_ID from env");
|
|
68
66
|
}
|
|
69
67
|
return v;
|
|
70
68
|
})();
|
|
71
|
-
const
|
|
72
|
-
const v = ciEnv["
|
|
69
|
+
const githubAppPrivateKey = (() => {
|
|
70
|
+
const v = ciEnv["_GITHUB_APP_PEM_CONTENT"];
|
|
73
71
|
if (!v) {
|
|
74
|
-
throw new Error("Missing
|
|
72
|
+
throw new Error("Missing _GITHUB_APP_PEM_CONTENT from env");
|
|
75
73
|
}
|
|
76
74
|
return v;
|
|
77
75
|
})();
|
|
78
|
-
return { githubAppAppId, githubAppInstallationId,
|
|
76
|
+
return { githubAppAppId, githubAppInstallationId, githubAppPrivateKey };
|
|
79
77
|
}
|
|
80
78
|
main()
|
|
81
79
|
.then(() => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ProtobufArtifactKeeperBackend, type ProtobufTargetLanguageOptions, ProtobufTargetLanguage } from "../types";
|
|
2
|
+
export declare class ArtifactKeeperProtobufCompilerBackend {
|
|
3
|
+
private readonly config;
|
|
4
|
+
constructor(config: ProtobufArtifactKeeperBackend);
|
|
5
|
+
publish({ generatedDirectory, targetLanguage, options, }: {
|
|
6
|
+
generatedDirectory: string;
|
|
7
|
+
targetLanguage: ProtobufTargetLanguage;
|
|
8
|
+
options: ProtobufTargetLanguageOptions;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
private publishJava;
|
|
11
|
+
private publishMaven;
|
|
12
|
+
private publishGradle;
|
|
13
|
+
private publishRust;
|
|
14
|
+
private moveJavaSources;
|
|
15
|
+
private findRustFiles;
|
|
16
|
+
private createMavenPom;
|
|
17
|
+
private createMavenSettings;
|
|
18
|
+
private createGradleBuild;
|
|
19
|
+
private createCargoToml;
|
|
20
|
+
private createRustLibrary;
|
|
21
|
+
private escapeXml;
|
|
22
|
+
private get artifactKeeperUrl();
|
|
23
|
+
private get mavenRepositoryUrl();
|
|
24
|
+
private get cargoIndexUrl();
|
|
25
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { $ } from "bun";
|
|
2
|
+
import { mkdir, mkdtemp, readdir, rename, rm, writeFile, } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { ProtobufTargetLanguage, } from "../types";
|
|
6
|
+
const DEFAULT_ARTIFACT_KEEPER_URL = "https://pkg.vpn.patinanetwork.org";
|
|
7
|
+
const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
|
|
8
|
+
const DEFAULT_PROST_VERSION = "0.14";
|
|
9
|
+
export class ArtifactKeeperProtobufCompilerBackend {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
async publish({ generatedDirectory, targetLanguage, options, }) {
|
|
15
|
+
switch (targetLanguage) {
|
|
16
|
+
case ProtobufTargetLanguage.JAVA:
|
|
17
|
+
await this.publishJava({
|
|
18
|
+
generatedDirectory,
|
|
19
|
+
options: options,
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
case ProtobufTargetLanguage.RUST:
|
|
23
|
+
await this.publishRust({
|
|
24
|
+
generatedDirectory,
|
|
25
|
+
options: options,
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
case ProtobufTargetLanguage.GO:
|
|
29
|
+
throw new Error("Artifact Keeper Go module publishing requires its upload workflow; only Go module consumption has been configured.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async publishJava({ generatedDirectory, options, }) {
|
|
33
|
+
await this.moveJavaSources(generatedDirectory);
|
|
34
|
+
if (options.buildTool === "gradle") {
|
|
35
|
+
await this.publishGradle({ generatedDirectory, options });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await this.publishMaven({ generatedDirectory, options });
|
|
39
|
+
}
|
|
40
|
+
async publishMaven({ generatedDirectory, options, }) {
|
|
41
|
+
await writeFile(path.join(generatedDirectory, "pom.xml"), this.createMavenPom(options));
|
|
42
|
+
const settingsDirectory = await mkdtemp(path.join(tmpdir(), "artifact-keeper-maven-"));
|
|
43
|
+
const settingsPath = path.join(settingsDirectory, "settings.xml");
|
|
44
|
+
await writeFile(settingsPath, this.createMavenSettings());
|
|
45
|
+
try {
|
|
46
|
+
await $ `mvn --settings ${settingsPath} deploy`.cwd(generatedDirectory);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await rm(settingsDirectory, { force: true, recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async publishGradle({ generatedDirectory, options, }) {
|
|
53
|
+
await Promise.all([
|
|
54
|
+
writeFile(path.join(generatedDirectory, "build.gradle"), this.createGradleBuild(options)),
|
|
55
|
+
writeFile(path.join(generatedDirectory, "settings.gradle"), `rootProject.name = "${options.artifactId}"\n`),
|
|
56
|
+
]);
|
|
57
|
+
await $ `gradle -PmavenUsername=${this.config.username} -PmavenPassword=${this.config.token} publish`.cwd(generatedDirectory);
|
|
58
|
+
}
|
|
59
|
+
async publishRust({ generatedDirectory, options, }) {
|
|
60
|
+
const generatedFiles = await this.findRustFiles(generatedDirectory);
|
|
61
|
+
await mkdir(path.join(generatedDirectory, "src"), { recursive: true });
|
|
62
|
+
await Promise.all([
|
|
63
|
+
writeFile(path.join(generatedDirectory, "Cargo.toml"), this.createCargoToml(options)),
|
|
64
|
+
writeFile(path.join(generatedDirectory, "src", "lib.rs"), this.createRustLibrary(generatedFiles)),
|
|
65
|
+
]);
|
|
66
|
+
await $ `cargo publish --registry cargo --token ${this.config.token} --config ${`registries.cargo.index=${this.cargoIndexUrl}`}`.cwd(generatedDirectory);
|
|
67
|
+
}
|
|
68
|
+
async moveJavaSources(generatedDirectory) {
|
|
69
|
+
const sourceDirectory = path.join(generatedDirectory, "src", "main", "java");
|
|
70
|
+
await mkdir(sourceDirectory, { recursive: true });
|
|
71
|
+
for (const entry of await readdir(generatedDirectory, {
|
|
72
|
+
withFileTypes: true,
|
|
73
|
+
})) {
|
|
74
|
+
if (entry.name === "src" ||
|
|
75
|
+
entry.name === "pom.xml" ||
|
|
76
|
+
entry.name === "build.gradle" ||
|
|
77
|
+
entry.name === "settings.gradle") {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
await rename(path.join(generatedDirectory, entry.name), path.join(sourceDirectory, entry.name));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async findRustFiles(directory, baseDirectory = directory) {
|
|
84
|
+
const files = [];
|
|
85
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
86
|
+
const filePath = path.join(directory, entry.name);
|
|
87
|
+
if (entry.isDirectory()) {
|
|
88
|
+
if (entry.name === "src")
|
|
89
|
+
continue;
|
|
90
|
+
files.push(...(await this.findRustFiles(filePath, baseDirectory)));
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (entry.isFile() && entry.name.endsWith(".rs")) {
|
|
94
|
+
files.push(path.relative(baseDirectory, filePath).split(path.sep).join("/"));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return files;
|
|
98
|
+
}
|
|
99
|
+
createMavenPom(options) {
|
|
100
|
+
const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
|
|
101
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
102
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
103
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
104
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
105
|
+
<modelVersion>4.0.0</modelVersion>
|
|
106
|
+
<groupId>${this.escapeXml(options.groupId)}</groupId>
|
|
107
|
+
<artifactId>${this.escapeXml(options.artifactId)}</artifactId>
|
|
108
|
+
<version>${this.escapeXml(options.version)}</version>
|
|
109
|
+
<properties>
|
|
110
|
+
<maven.compiler.release>17</maven.compiler.release>
|
|
111
|
+
</properties>
|
|
112
|
+
<dependencies>
|
|
113
|
+
<dependency>
|
|
114
|
+
<groupId>com.google.protobuf</groupId>
|
|
115
|
+
<artifactId>protobuf-java</artifactId>
|
|
116
|
+
<version>${this.escapeXml(protobufVersion)}</version>
|
|
117
|
+
</dependency>
|
|
118
|
+
</dependencies>
|
|
119
|
+
<distributionManagement>
|
|
120
|
+
<repository>
|
|
121
|
+
<id>maven</id>
|
|
122
|
+
<url>${this.escapeXml(this.mavenRepositoryUrl)}</url>
|
|
123
|
+
</repository>
|
|
124
|
+
</distributionManagement>
|
|
125
|
+
</project>
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
createMavenSettings() {
|
|
129
|
+
return `<settings>
|
|
130
|
+
<servers>
|
|
131
|
+
<server>
|
|
132
|
+
<id>maven</id>
|
|
133
|
+
<username>${this.escapeXml(this.config.username)}</username>
|
|
134
|
+
<password>${this.escapeXml(this.config.token)}</password>
|
|
135
|
+
</server>
|
|
136
|
+
</servers>
|
|
137
|
+
</settings>
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
createGradleBuild(options) {
|
|
141
|
+
const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
|
|
142
|
+
return `plugins {
|
|
143
|
+
id "java"
|
|
144
|
+
id "maven-publish"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
group = "${options.groupId}"
|
|
148
|
+
version = "${options.version}"
|
|
149
|
+
|
|
150
|
+
repositories {
|
|
151
|
+
mavenCentral()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
dependencies {
|
|
155
|
+
implementation "com.google.protobuf:protobuf-java:${protobufVersion}"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
java {
|
|
159
|
+
toolchain {
|
|
160
|
+
languageVersion = JavaLanguageVersion.of(17)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
publishing {
|
|
165
|
+
publications {
|
|
166
|
+
mavenJava(MavenPublication) {
|
|
167
|
+
from components.java
|
|
168
|
+
artifactId = "${options.artifactId}"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
repositories {
|
|
172
|
+
maven {
|
|
173
|
+
url = uri("${this.mavenRepositoryUrl}")
|
|
174
|
+
credentials {
|
|
175
|
+
username = project.findProperty("mavenUsername")
|
|
176
|
+
password = project.findProperty("mavenPassword")
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
createCargoToml(options) {
|
|
184
|
+
const prostVersion = options.prostVersion ?? DEFAULT_PROST_VERSION;
|
|
185
|
+
return `[package]
|
|
186
|
+
name = "${options.crateName}"
|
|
187
|
+
version = "${options.version}"
|
|
188
|
+
edition = "2021"
|
|
189
|
+
|
|
190
|
+
[dependencies]
|
|
191
|
+
prost = "${prostVersion}"
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
createRustLibrary(generatedFiles) {
|
|
195
|
+
return generatedFiles
|
|
196
|
+
.map((relativePath) => {
|
|
197
|
+
const moduleName = relativePath
|
|
198
|
+
.replace(/\.rs$/, "")
|
|
199
|
+
.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
200
|
+
return `pub mod ${moduleName} {
|
|
201
|
+
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/${relativePath}"));
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
})
|
|
205
|
+
.join("\n");
|
|
206
|
+
}
|
|
207
|
+
escapeXml(value) {
|
|
208
|
+
return value.replace(/[<>&'"]/g, (character) => {
|
|
209
|
+
switch (character) {
|
|
210
|
+
case "<":
|
|
211
|
+
return "<";
|
|
212
|
+
case ">":
|
|
213
|
+
return ">";
|
|
214
|
+
case "&":
|
|
215
|
+
return "&";
|
|
216
|
+
case "'":
|
|
217
|
+
return "'";
|
|
218
|
+
case '"':
|
|
219
|
+
return """;
|
|
220
|
+
default:
|
|
221
|
+
return character;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
get artifactKeeperUrl() {
|
|
226
|
+
return (this.config.url ?? DEFAULT_ARTIFACT_KEEPER_URL).replace(/\/$/, "");
|
|
227
|
+
}
|
|
228
|
+
get mavenRepositoryUrl() {
|
|
229
|
+
return `${this.artifactKeeperUrl}/maven/maven/`;
|
|
230
|
+
}
|
|
231
|
+
get cargoIndexUrl() {
|
|
232
|
+
return `${this.artifactKeeperUrl}/cargo/cargo/index`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./artifact-keeper";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./artifact-keeper";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { GitHubClient } from "../gh";
|
|
2
1
|
import { type ProtobufCompilerCompileArgs, type ProtobufCompilerCompileResult } from "./types";
|
|
3
2
|
export declare class ProtobufCompilerClient {
|
|
4
|
-
|
|
5
|
-
constructor(githubClient: GitHubClient);
|
|
6
|
-
compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }: ProtobufCompilerCompileArgs): Promise<ProtobufCompilerCompileResult>;
|
|
3
|
+
compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }: ProtobufCompilerCompileArgs): Promise<ProtobufCompilerCompileResult>;
|
|
7
4
|
installToolchains(): Promise<void>;
|
|
8
5
|
private generateWithBuf;
|
|
9
6
|
private getCompilationTargets;
|
|
@@ -11,6 +8,4 @@ export declare class ProtobufCompilerClient {
|
|
|
11
8
|
private getTargetLanguageStrategy;
|
|
12
9
|
private getBufGenerateInput;
|
|
13
10
|
private findBufModuleDirectory;
|
|
14
|
-
private uploadGeneratedDirectory;
|
|
15
|
-
private parseGitHubRepository;
|
|
16
11
|
}
|
package/dist/protobuf/client.js
CHANGED
|
@@ -4,18 +4,16 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import yaml from "yaml";
|
|
6
6
|
import { isCmdAvailable } from "../utils/cmd";
|
|
7
|
+
import { ArtifactKeeperProtobufCompilerBackend } from "./backend";
|
|
7
8
|
import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
|
|
8
9
|
import { ProtobufTargetLanguage, } from "./types";
|
|
9
10
|
export class ProtobufCompilerClient {
|
|
10
|
-
|
|
11
|
-
constructor(githubClient) {
|
|
12
|
-
this.githubClient = githubClient;
|
|
13
|
-
}
|
|
14
|
-
async compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
|
|
11
|
+
async compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
|
|
15
12
|
await this.installToolchains();
|
|
16
13
|
const outputDirectoryPath = path.resolve(outputDirectory ??
|
|
17
14
|
(await mkdtemp(path.join(tmpdir(), "protobuf-compiler-"))));
|
|
18
15
|
const targets = this.getCompilationTargets(targetLanguages);
|
|
16
|
+
const artifactKeeper = backend ? new ArtifactKeeperProtobufCompilerBackend(backend) : undefined;
|
|
19
17
|
await mkdir(outputDirectoryPath, { recursive: true });
|
|
20
18
|
await this.generateWithBuf({
|
|
21
19
|
bufToken,
|
|
@@ -27,17 +25,18 @@ export class ProtobufCompilerClient {
|
|
|
27
25
|
for (const { language, strategy } of targets) {
|
|
28
26
|
generatedDirectories[language] = path.join(outputDirectoryPath, strategy.outputDirectoryName);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
if (artifactKeeper) {
|
|
29
|
+
for (const { language, options } of targets) {
|
|
30
|
+
const generatedDirectory = generatedDirectories[language];
|
|
31
|
+
if (!generatedDirectory) {
|
|
32
|
+
throw new Error("Generated code directory was not created.");
|
|
33
|
+
}
|
|
34
|
+
await artifactKeeper.publish({
|
|
35
|
+
generatedDirectory,
|
|
36
|
+
options,
|
|
37
|
+
targetLanguage: language,
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
|
-
await this.uploadGeneratedDirectory({
|
|
38
|
-
generatedDirectory,
|
|
39
|
-
options,
|
|
40
|
-
});
|
|
41
40
|
}
|
|
42
41
|
return { generatedDirectories, outputDirectory: outputDirectoryPath };
|
|
43
42
|
}
|
|
@@ -124,31 +123,4 @@ export class ProtobufCompilerClient {
|
|
|
124
123
|
currentDirectory = parentDirectory;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
|
-
async uploadGeneratedDirectory({ generatedDirectory, options, }) {
|
|
128
|
-
if (!options.uploadLocation) {
|
|
129
|
-
throw new Error("An upload location is required to upload generated code.");
|
|
130
|
-
}
|
|
131
|
-
const repository = this.parseGitHubRepository(options.uploadLocation, options.directory);
|
|
132
|
-
await this.githubClient.DANGEROUS__uploadDirectoryContents({
|
|
133
|
-
owner: repository.owner,
|
|
134
|
-
repository: repository.repository,
|
|
135
|
-
directory: repository.directory,
|
|
136
|
-
sourceDirectory: generatedDirectory,
|
|
137
|
-
message: options.commitMessage ?? "chore: update generated protobuf clients",
|
|
138
|
-
branch: options.branch,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
parseGitHubRepository(uploadLocation, directory) {
|
|
142
|
-
const [owner, repository, ...pathParts] = uploadLocation
|
|
143
|
-
.split("/")
|
|
144
|
-
.filter(Boolean);
|
|
145
|
-
if (!owner || !repository) {
|
|
146
|
-
throw new Error("GitHub upload location must be in the form `owner/repo` or `owner/repo/path`.");
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
directory: directory ?? pathParts.join("/"),
|
|
150
|
-
owner,
|
|
151
|
-
repository,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
126
|
}
|
package/dist/protobuf/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare enum ProtobufCompilerBackend {
|
|
2
|
+
ARTIFACT_KEEPER = 0
|
|
3
|
+
}
|
|
1
4
|
export declare enum ProtobufSourceLanguage {
|
|
2
5
|
RUST = 0
|
|
3
6
|
}
|
|
@@ -6,35 +9,41 @@ export declare enum ProtobufTargetLanguage {
|
|
|
6
9
|
RUST = 1,
|
|
7
10
|
GO = 2
|
|
8
11
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
export interface ProtobufArtifactKeeperBackend {
|
|
13
|
+
type: ProtobufCompilerBackend.ARTIFACT_KEEPER;
|
|
14
|
+
/** Defaults to `https://pkg.vpn.patinanetwork.org`. */
|
|
15
|
+
url?: string;
|
|
16
|
+
username: string;
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ProtobufJavaTargetLanguageOptions {
|
|
20
|
+
groupId: string;
|
|
21
|
+
artifactId: string;
|
|
22
|
+
version: string;
|
|
23
|
+
buildTool?: "maven" | "gradle";
|
|
24
|
+
protobufJavaVersion?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ProtobufRustTargetLanguageOptions {
|
|
27
|
+
crateName: string;
|
|
28
|
+
version: string;
|
|
29
|
+
prostVersion?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ProtobufGoTargetLanguageOptions {
|
|
32
|
+
modulePath: string;
|
|
33
|
+
version: string;
|
|
34
|
+
}
|
|
35
|
+
export type ProtobufTargetLanguageOptions = ProtobufGoTargetLanguageOptions | ProtobufJavaTargetLanguageOptions | ProtobufRustTargetLanguageOptions;
|
|
36
|
+
export type ProtobufTargetLanguages = {
|
|
37
|
+
[ProtobufTargetLanguage.JAVA]?: ProtobufJavaTargetLanguageOptions;
|
|
38
|
+
[ProtobufTargetLanguage.RUST]?: ProtobufRustTargetLanguageOptions;
|
|
39
|
+
[ProtobufTargetLanguage.GO]?: ProtobufGoTargetLanguageOptions;
|
|
40
|
+
};
|
|
22
41
|
export interface ProtobufCompilerCompileArgs {
|
|
42
|
+
/** All targets are published through this one backend. */
|
|
43
|
+
backend?: ProtobufArtifactKeeperBackend;
|
|
23
44
|
sourceLanguage: ProtobufSourceLanguage;
|
|
24
45
|
/** Optional BSR API token used for Buf remote plugins. */
|
|
25
46
|
bufToken?: string;
|
|
26
|
-
/**
|
|
27
|
-
* A map of target language to target-specific options.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* {
|
|
32
|
-
* [ProtobufTargetLanguage.JAVA]: {
|
|
33
|
-
* uploadLocation: "Patina-Network/proto-clients/java",
|
|
34
|
-
* },
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
47
|
targetLanguages: ProtobufTargetLanguages;
|
|
39
48
|
/** Directory containing proto files, or one specific `.proto` file. */
|
|
40
49
|
protoFilesLocation: string;
|
package/dist/protobuf/types.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export var ProtobufCompilerBackend;
|
|
2
|
+
(function (ProtobufCompilerBackend) {
|
|
3
|
+
ProtobufCompilerBackend[ProtobufCompilerBackend["ARTIFACT_KEEPER"] = 0] = "ARTIFACT_KEEPER";
|
|
4
|
+
})(ProtobufCompilerBackend || (ProtobufCompilerBackend = {}));
|
|
1
5
|
export var ProtobufSourceLanguage;
|
|
2
6
|
(function (ProtobufSourceLanguage) {
|
|
3
7
|
ProtobufSourceLanguage[ProtobufSourceLanguage["RUST"] = 0] = "RUST";
|
package/dist/utils/cmd.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fromPromise } from "neverthrow";
|
|
|
3
3
|
const GENERIC_ERROR = 1;
|
|
4
4
|
const SUCCESS = 0;
|
|
5
5
|
export async function isCmdAvailable(cmd) {
|
|
6
|
-
return ((await fromPromise($ `which
|
|
6
|
+
return ((await fromPromise($ `which ${cmd}`.quiet(), (e) => e)
|
|
7
7
|
.map((s) => s.exitCode)
|
|
8
8
|
.unwrapOr(GENERIC_ERROR)) === SUCCESS);
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"author": "Tahmid Ahmed",
|
|
5
5
|
"description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
|
|
6
|
-
"version": "1.0.76-beta.
|
|
6
|
+
"version": "1.0.76-beta.0f9c2cb9",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "git+https://github.com/tahminator/pipeline.git"
|
|
9
9
|
},
|