@tahminator/pipeline 1.0.76-beta.6560b5dd → 1.0.76-beta.7c6d310b

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 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,25 @@ 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, then optionally upload them to a GitHub repository path. The client installs Buf globally with npm when necessary.
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 gh = await GitHubClient.createWithGithubAppToken({
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
+ url: process.env.ARTIFACT_KEEPER_URL!,
198
+ username: process.env.ARTIFACT_KEEPER_USERNAME!,
199
+ },
198
200
  sourceLanguage: ProtobufSourceLanguage.RUST,
199
201
  bufToken: process.env.BUF_TOKEN,
200
202
  targetLanguages: {
201
203
  [ProtobufTargetLanguage.JAVA]: {
202
- uploadLocation: "Patina-Network/proto-clients/java",
204
+ artifactId: "hello-world-grpc-service",
205
+ groupId: "org.my-org",
206
+ version: "1.0.0",
203
207
  },
204
208
  },
205
209
  protoFilesLocation: "./proto",
@@ -388,6 +392,7 @@ Utilities to compute the next semver tag from GitHub and update versions in code
388
392
  ```ts
389
393
  const gh = await GitHubClient.createWithDefaultCiToken();
390
394
 
395
+ // available strategies: JSTS, JAVA_MAVEN, RUST_CARGO, NONE
391
396
  const versioning = new VersioningClient(gh, VersionUpdatingStrategy.JSTS);
392
397
 
393
398
  // if your repo has no tags yet, this will return `1.0.0`
@@ -0,0 +1,22 @@
1
+ import type { IProtobufCompilerBackendStrategy, ProtobufCompilerBackendPublishArgs } from "./types";
2
+ import { type ProtobufArtifactKeeperBackend } from "../types";
3
+ export declare class ArtifactKeeperProtobufCompilerBackend implements IProtobufCompilerBackendStrategy {
4
+ private readonly config;
5
+ constructor(config: ProtobufArtifactKeeperBackend);
6
+ publish({ generatedDirectory, targetLanguage, options, }: ProtobufCompilerBackendPublishArgs): Promise<void>;
7
+ private publishJava;
8
+ private publishMaven;
9
+ private publishGradle;
10
+ private publishRust;
11
+ private moveJavaSources;
12
+ private findRustFiles;
13
+ private createMavenPom;
14
+ private createMavenSettings;
15
+ private createGradleBuild;
16
+ private createCargoToml;
17
+ private createRustLibrary;
18
+ private escapeXml;
19
+ private get artifactKeeperUrl();
20
+ private get mavenRepositoryUrl();
21
+ private get cargoIndexUrl();
22
+ }
@@ -0,0 +1,233 @@
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_PROTOBUF_JAVA_VERSION = "4.32.1";
7
+ const DEFAULT_PROST_VERSION = "0.14";
8
+ export class ArtifactKeeperProtobufCompilerBackend {
9
+ config;
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ async publish({ generatedDirectory, targetLanguage, options, }) {
14
+ switch (targetLanguage) {
15
+ case ProtobufTargetLanguage.JAVA:
16
+ await this.publishJava({
17
+ generatedDirectory,
18
+ options: options,
19
+ });
20
+ return;
21
+ case ProtobufTargetLanguage.RUST:
22
+ await this.publishRust({
23
+ generatedDirectory,
24
+ options: options,
25
+ });
26
+ return;
27
+ case ProtobufTargetLanguage.GO:
28
+ throw new Error("Artifact Keeper Go module publishing requires its upload workflow; only Go module consumption has been configured.");
29
+ }
30
+ }
31
+ async publishJava({ generatedDirectory, options, }) {
32
+ await this.moveJavaSources(generatedDirectory);
33
+ if (options.buildTool === "gradle") {
34
+ await this.publishGradle({ generatedDirectory, options });
35
+ return;
36
+ }
37
+ await this.publishMaven({ generatedDirectory, options });
38
+ }
39
+ async publishMaven({ generatedDirectory, options, }) {
40
+ await writeFile(path.join(generatedDirectory, "pom.xml"), this.createMavenPom(options));
41
+ const settingsDirectory = await mkdtemp(path.join(tmpdir(), "artifact-keeper-maven-"));
42
+ const settingsPath = path.join(settingsDirectory, "settings.xml");
43
+ await writeFile(settingsPath, this.createMavenSettings());
44
+ try {
45
+ await $ `mvn --settings ${settingsPath} deploy`.cwd(generatedDirectory);
46
+ }
47
+ finally {
48
+ await rm(settingsDirectory, { force: true, recursive: true });
49
+ }
50
+ }
51
+ async publishGradle({ generatedDirectory, options, }) {
52
+ await Promise.all([
53
+ writeFile(path.join(generatedDirectory, "build.gradle"), this.createGradleBuild(options)),
54
+ writeFile(path.join(generatedDirectory, "settings.gradle"), `rootProject.name = "${options.artifactId}"\n`),
55
+ ]);
56
+ await $ `gradle -PmavenUsername=${this.config.username} -PmavenPassword=${this.config.token} publish`.cwd(generatedDirectory);
57
+ }
58
+ async publishRust({ generatedDirectory, options, }) {
59
+ const generatedFiles = await this.findRustFiles(generatedDirectory);
60
+ await mkdir(path.join(generatedDirectory, "src"), { recursive: true });
61
+ await Promise.all([
62
+ writeFile(path.join(generatedDirectory, "Cargo.toml"), this.createCargoToml(options)),
63
+ writeFile(path.join(generatedDirectory, "src", "lib.rs"), this.createRustLibrary(generatedFiles)),
64
+ ]);
65
+ await $ `cargo publish --registry cargo --token ${this.config.token} --config ${`registries.cargo.index=${this.cargoIndexUrl}`}`.cwd(generatedDirectory);
66
+ }
67
+ async moveJavaSources(generatedDirectory) {
68
+ const sourceDirectory = path.join(generatedDirectory, "src", "main", "java");
69
+ await mkdir(sourceDirectory, { recursive: true });
70
+ for (const entry of await readdir(generatedDirectory, {
71
+ withFileTypes: true,
72
+ })) {
73
+ if (entry.name === "src" ||
74
+ entry.name === "pom.xml" ||
75
+ entry.name === "build.gradle" ||
76
+ entry.name === "settings.gradle") {
77
+ continue;
78
+ }
79
+ await rename(path.join(generatedDirectory, entry.name), path.join(sourceDirectory, entry.name));
80
+ }
81
+ }
82
+ async findRustFiles(directory, baseDirectory = directory) {
83
+ const files = [];
84
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
85
+ const filePath = path.join(directory, entry.name);
86
+ if (entry.isDirectory()) {
87
+ if (entry.name === "src")
88
+ continue;
89
+ files.push(...(await this.findRustFiles(filePath, baseDirectory)));
90
+ continue;
91
+ }
92
+ if (entry.isFile() && entry.name.endsWith(".rs")) {
93
+ files.push(path.relative(baseDirectory, filePath).split(path.sep).join("/"));
94
+ }
95
+ }
96
+ return files;
97
+ }
98
+ createMavenPom(options) {
99
+ const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
100
+ return `<?xml version="1.0" encoding="UTF-8"?>
101
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
102
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
103
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
104
+ <modelVersion>4.0.0</modelVersion>
105
+ <groupId>${this.escapeXml(options.groupId)}</groupId>
106
+ <artifactId>${this.escapeXml(options.artifactId)}</artifactId>
107
+ <version>${this.escapeXml(options.version)}</version>
108
+ <properties>
109
+ <maven.compiler.release>17</maven.compiler.release>
110
+ </properties>
111
+ <dependencies>
112
+ <dependency>
113
+ <groupId>com.google.protobuf</groupId>
114
+ <artifactId>protobuf-java</artifactId>
115
+ <version>${this.escapeXml(protobufVersion)}</version>
116
+ </dependency>
117
+ </dependencies>
118
+ <distributionManagement>
119
+ <repository>
120
+ <id>maven</id>
121
+ <url>${this.escapeXml(this.mavenRepositoryUrl)}</url>
122
+ </repository>
123
+ </distributionManagement>
124
+ </project>
125
+ `;
126
+ }
127
+ createMavenSettings() {
128
+ return `<settings>
129
+ <servers>
130
+ <server>
131
+ <id>maven</id>
132
+ <username>${this.escapeXml(this.config.username)}</username>
133
+ <password>${this.escapeXml(this.config.token)}</password>
134
+ </server>
135
+ </servers>
136
+ </settings>
137
+ `;
138
+ }
139
+ createGradleBuild(options) {
140
+ const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
141
+ return `plugins {
142
+ id "java"
143
+ id "maven-publish"
144
+ }
145
+
146
+ group = "${options.groupId}"
147
+ version = "${options.version}"
148
+
149
+ repositories {
150
+ mavenCentral()
151
+ }
152
+
153
+ dependencies {
154
+ implementation "com.google.protobuf:protobuf-java:${protobufVersion}"
155
+ }
156
+
157
+ java {
158
+ toolchain {
159
+ languageVersion = JavaLanguageVersion.of(17)
160
+ }
161
+ }
162
+
163
+ publishing {
164
+ publications {
165
+ mavenJava(MavenPublication) {
166
+ from components.java
167
+ artifactId = "${options.artifactId}"
168
+ }
169
+ }
170
+ repositories {
171
+ maven {
172
+ url = uri("${this.mavenRepositoryUrl}")
173
+ credentials {
174
+ username = project.findProperty("mavenUsername")
175
+ password = project.findProperty("mavenPassword")
176
+ }
177
+ }
178
+ }
179
+ }
180
+ `;
181
+ }
182
+ createCargoToml(options) {
183
+ const prostVersion = options.prostVersion ?? DEFAULT_PROST_VERSION;
184
+ return `[package]
185
+ name = "${options.crateName}"
186
+ version = "${options.version}"
187
+ edition = "2021"
188
+
189
+ [dependencies]
190
+ prost = "${prostVersion}"
191
+ `;
192
+ }
193
+ createRustLibrary(generatedFiles) {
194
+ return generatedFiles
195
+ .map((relativePath) => {
196
+ const moduleName = relativePath
197
+ .replace(/\.rs$/, "")
198
+ .replace(/[^a-zA-Z0-9_]/g, "_");
199
+ return `pub mod ${moduleName} {
200
+ include!(concat!(env!("CARGO_MANIFEST_DIR"), "/${relativePath}"));
201
+ }
202
+ `;
203
+ })
204
+ .join("\n");
205
+ }
206
+ escapeXml(value) {
207
+ return value.replace(/[<>&'"]/g, (character) => {
208
+ switch (character) {
209
+ case "<":
210
+ return "&lt;";
211
+ case ">":
212
+ return "&gt;";
213
+ case "&":
214
+ return "&amp;";
215
+ case "'":
216
+ return "&apos;";
217
+ case '"':
218
+ return "&quot;";
219
+ default:
220
+ return character;
221
+ }
222
+ });
223
+ }
224
+ get artifactKeeperUrl() {
225
+ return this.config.url.replace(/\/$/, "");
226
+ }
227
+ get mavenRepositoryUrl() {
228
+ return `${this.artifactKeeperUrl}/maven/maven/`;
229
+ }
230
+ get cargoIndexUrl() {
231
+ return `${this.artifactKeeperUrl}/cargo/cargo/index`;
232
+ }
233
+ }
@@ -0,0 +1,5 @@
1
+ import type { IProtobufCompilerBackendStrategy } from "./types";
2
+ import { type ProtobufCompilerBackendConfig } from "../types";
3
+ export * from "./artifact-keeper";
4
+ export * from "./types";
5
+ export declare function createProtobufCompilerBackendStrategy(backend: ProtobufCompilerBackendConfig): IProtobufCompilerBackendStrategy;
@@ -0,0 +1,10 @@
1
+ import { ProtobufCompilerBackend, } from "../types";
2
+ import { ArtifactKeeperProtobufCompilerBackend } from "./artifact-keeper";
3
+ export * from "./artifact-keeper";
4
+ export * from "./types";
5
+ const BACKEND_STRATEGY_FACTORIES = {
6
+ [ProtobufCompilerBackend.ARTIFACT_KEEPER]: (backend) => new ArtifactKeeperProtobufCompilerBackend(backend),
7
+ };
8
+ export function createProtobufCompilerBackendStrategy(backend) {
9
+ return BACKEND_STRATEGY_FACTORIES[backend.type](backend);
10
+ }
@@ -0,0 +1,9 @@
1
+ import type { ProtobufTargetLanguage, ProtobufTargetLanguageOptions } from "../types";
2
+ export interface ProtobufCompilerBackendPublishArgs {
3
+ generatedDirectory: string;
4
+ targetLanguage: ProtobufTargetLanguage;
5
+ options: ProtobufTargetLanguageOptions;
6
+ }
7
+ export interface IProtobufCompilerBackendStrategy {
8
+ publish(args: ProtobufCompilerBackendPublishArgs): Promise<void>;
9
+ }
File without changes
@@ -1,16 +1,10 @@
1
- import type { GitHubClient } from "../gh";
2
1
  import { type ProtobufCompilerCompileArgs, type ProtobufCompilerCompileResult } from "./types";
3
2
  export declare class ProtobufCompilerClient {
4
- private readonly githubClient;
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;
10
7
  private getConfiguredTargetLanguages;
11
- private getTargetLanguageStrategy;
12
8
  private getBufGenerateInput;
13
9
  private findBufModuleDirectory;
14
- private uploadGeneratedDirectory;
15
- private parseGitHubRepository;
16
10
  }
@@ -4,18 +4,21 @@ 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 { createProtobufCompilerBackendStrategy } from "./backend";
7
8
  import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
8
9
  import { ProtobufTargetLanguage, } from "./types";
10
+ const TARGET_LANGUAGE_STRATEGY_FACTORIES = {
11
+ [ProtobufTargetLanguage.JAVA]: () => new JavaProtobufTargetLanguageStrategy(),
12
+ [ProtobufTargetLanguage.GO]: () => new GoProtobufTargetLanguageStrategy(),
13
+ [ProtobufTargetLanguage.RUST]: () => new RustProtobufTargetLanguageStrategy(),
14
+ };
9
15
  export class ProtobufCompilerClient {
10
- githubClient;
11
- constructor(githubClient) {
12
- this.githubClient = githubClient;
13
- }
14
- async compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
16
+ async compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
15
17
  await this.installToolchains();
16
18
  const outputDirectoryPath = path.resolve(outputDirectory ??
17
19
  (await mkdtemp(path.join(tmpdir(), "protobuf-compiler-"))));
18
20
  const targets = this.getCompilationTargets(targetLanguages);
21
+ const compilerBackend = backend ? createProtobufCompilerBackendStrategy(backend) : undefined;
19
22
  await mkdir(outputDirectoryPath, { recursive: true });
20
23
  await this.generateWithBuf({
21
24
  bufToken,
@@ -27,17 +30,18 @@ export class ProtobufCompilerClient {
27
30
  for (const { language, strategy } of targets) {
28
31
  generatedDirectories[language] = path.join(outputDirectoryPath, strategy.outputDirectoryName);
29
32
  }
30
- for (const { language, options } of targets) {
31
- if (!options.uploadLocation)
32
- continue;
33
- const generatedDirectory = generatedDirectories[language];
34
- if (!generatedDirectory) {
35
- throw new Error("Generated code directory was not created.");
33
+ if (compilerBackend) {
34
+ for (const { language, options } of targets) {
35
+ const generatedDirectory = generatedDirectories[language];
36
+ if (!generatedDirectory) {
37
+ throw new Error("Generated code directory was not created.");
38
+ }
39
+ await compilerBackend.publish({
40
+ generatedDirectory,
41
+ options,
42
+ targetLanguage: language,
43
+ });
36
44
  }
37
- await this.uploadGeneratedDirectory({
38
- generatedDirectory,
39
- options,
40
- });
41
45
  }
42
46
  return { generatedDirectories, outputDirectory: outputDirectoryPath };
43
47
  }
@@ -76,27 +80,11 @@ export class ProtobufCompilerClient {
76
80
  return this.getConfiguredTargetLanguages(targetLanguages).map(([language, options]) => ({
77
81
  language,
78
82
  options,
79
- strategy: this.getTargetLanguageStrategy(language),
83
+ strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](),
80
84
  }));
81
85
  }
82
86
  getConfiguredTargetLanguages(targetLanguages) {
83
- const targets = [];
84
- for (const [language, options] of Object.entries(targetLanguages)) {
85
- if (!options)
86
- continue;
87
- targets.push([Number(language), options]);
88
- }
89
- return targets;
90
- }
91
- getTargetLanguageStrategy(targetLanguage) {
92
- switch (targetLanguage) {
93
- case ProtobufTargetLanguage.JAVA:
94
- return new JavaProtobufTargetLanguageStrategy();
95
- case ProtobufTargetLanguage.GO:
96
- return new GoProtobufTargetLanguageStrategy();
97
- case ProtobufTargetLanguage.RUST:
98
- return new RustProtobufTargetLanguageStrategy();
99
- }
87
+ return Object.entries(targetLanguages).flatMap(([language, options]) => options ? [[Number(language), options]] : []);
100
88
  }
101
89
  async getBufGenerateInput(protoFilesLocation) {
102
90
  const resolvedLocation = path.resolve(protoFilesLocation);
@@ -124,31 +112,4 @@ export class ProtobufCompilerClient {
124
112
  currentDirectory = parentDirectory;
125
113
  }
126
114
  }
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
115
  }
@@ -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 ProtobufTargetLanguageOptions {
10
- /**
11
- * Either `owner/repo` or `owner/repo/path/inside/repo`.
12
- *
13
- * @example "Patina-Network/proto-clients/java"
14
- */
15
- uploadLocation?: string;
16
- /** Overrides the path parsed from `uploadLocation`. */
17
- directory?: string;
18
- branch?: string;
19
- commitMessage?: string;
20
- }
21
- export type ProtobufTargetLanguages = Partial<Record<ProtobufTargetLanguage, ProtobufTargetLanguageOptions>>;
12
+ export interface ProtobufArtifactKeeperBackend {
13
+ type: ProtobufCompilerBackend.ARTIFACT_KEEPER;
14
+ url: string;
15
+ username: string;
16
+ token: string;
17
+ }
18
+ export type ProtobufCompilerBackendConfig = ProtobufArtifactKeeperBackend;
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?: ProtobufCompilerBackendConfig;
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;
@@ -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 -v ${cmd}`.quiet(), (e) => e)
6
+ return ((await fromPromise($ `which ${cmd}`.quiet(), (e) => e)
7
7
  .map((s) => s.exitCode)
8
8
  .unwrapOr(GENERIC_ERROR)) === SUCCESS);
9
9
  }
@@ -3,6 +3,7 @@ import { VersionUpdatingStrategy, } from "./types";
3
3
  import { JavaMavenVersioningClient } from "./updating/java/maven";
4
4
  import { JavascriptPackageJsonVersioningClient } from "./updating/jsts";
5
5
  import { NoneVersioningClient } from "./updating/none";
6
+ import { RustCargoVersioningClient } from "./updating/rust/cargo";
6
7
  export class VersioningClient {
7
8
  githubClient;
8
9
  static INITIAL_VERSION = "1.0.0";
@@ -17,6 +18,8 @@ export class VersioningClient {
17
18
  return new JavascriptPackageJsonVersioningClient();
18
19
  case VersionUpdatingStrategy.JAVA_MAVEN:
19
20
  return new JavaMavenVersioningClient();
21
+ case VersionUpdatingStrategy.RUST_CARGO:
22
+ return new RustCargoVersioningClient();
20
23
  case VersionUpdatingStrategy.NONE:
21
24
  return new NoneVersioningClient();
22
25
  }
@@ -1,7 +1,8 @@
1
1
  export declare enum VersionUpdatingStrategy {
2
2
  JSTS = 0,
3
3
  JAVA_MAVEN = 1,
4
- NONE = 2
4
+ RUST_CARGO = 2,
5
+ NONE = 3
5
6
  }
6
7
  export interface IVersionUpdatingClient {
7
8
  update(version: string): Promise<void>;
@@ -37,3 +38,5 @@ export interface IJavascriptPackageJsonVersionUpdatingClient extends IVersionUpd
37
38
  }
38
39
  export interface IJavaMavenVersionUpdatingClient extends IVersionUpdatingClient {
39
40
  }
41
+ export interface IRustCargoVersionUpdatingClient extends IVersionUpdatingClient {
42
+ }
@@ -2,5 +2,6 @@ export var VersionUpdatingStrategy;
2
2
  (function (VersionUpdatingStrategy) {
3
3
  VersionUpdatingStrategy[VersionUpdatingStrategy["JSTS"] = 0] = "JSTS";
4
4
  VersionUpdatingStrategy[VersionUpdatingStrategy["JAVA_MAVEN"] = 1] = "JAVA_MAVEN";
5
- VersionUpdatingStrategy[VersionUpdatingStrategy["NONE"] = 2] = "NONE";
5
+ VersionUpdatingStrategy[VersionUpdatingStrategy["RUST_CARGO"] = 2] = "RUST_CARGO";
6
+ VersionUpdatingStrategy[VersionUpdatingStrategy["NONE"] = 3] = "NONE";
6
7
  })(VersionUpdatingStrategy || (VersionUpdatingStrategy = {}));
@@ -0,0 +1,6 @@
1
+ import type { IRustCargoVersionUpdatingClient } from "../../../types";
2
+ import { BaseVersionUpdatingClient } from "../../base";
3
+ export declare class RustCargoVersioningClient extends BaseVersionUpdatingClient implements IRustCargoVersionUpdatingClient {
4
+ update(version: string): Promise<void>;
5
+ private updatePackageVersionInCargoToml;
6
+ }
@@ -0,0 +1,50 @@
1
+ import { BaseVersionUpdatingClient } from "../../base";
2
+ export class RustCargoVersioningClient extends BaseVersionUpdatingClient {
3
+ async update(version) {
4
+ const files = await this.findFiles("**/Cargo.toml");
5
+ for (const fileLocation of files) {
6
+ const file = Bun.file(fileLocation);
7
+ const oldCargoToml = await file.text();
8
+ const newCargoToml = this.updatePackageVersionInCargoToml(oldCargoToml, version);
9
+ if (!newCargoToml) {
10
+ continue;
11
+ }
12
+ await Bun.write(fileLocation, newCargoToml);
13
+ this.logFileLocationUpdated(fileLocation, version);
14
+ }
15
+ }
16
+ updatePackageVersionInCargoToml(cargoToml, version) {
17
+ const lines = cargoToml.split("\n");
18
+ let insidePackageSection = false;
19
+ let packageSectionFound = false;
20
+ let packageVersionLineIndex = -1;
21
+ for (let index = 0; index < lines.length; index++) {
22
+ const line = lines[index];
23
+ if (!line)
24
+ continue;
25
+ const sectionMatch = line.match(/^\s*\[(.+)\]\s*$/);
26
+ if (sectionMatch) {
27
+ const sectionName = sectionMatch[1]?.trim();
28
+ insidePackageSection = sectionName === "package";
29
+ if (insidePackageSection) {
30
+ packageSectionFound = true;
31
+ }
32
+ continue;
33
+ }
34
+ if (!insidePackageSection)
35
+ continue;
36
+ if (/^\s*version(?:\.[A-Za-z0-9_-]+)?\s*=/.test(line)) {
37
+ packageVersionLineIndex = index;
38
+ break;
39
+ }
40
+ }
41
+ if (!packageSectionFound) {
42
+ return null;
43
+ }
44
+ if (packageVersionLineIndex === -1) {
45
+ throw new Error("Can't find version key inside of package section in Cargo.toml");
46
+ }
47
+ lines[packageVersionLineIndex] = `version = "${version}"`;
48
+ return `${lines.join("\n").replace(/\n*$/, "\n")}`;
49
+ }
50
+ }
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.6560b5dd",
6
+ "version": "1.0.76-beta.7c6d310b",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },