@tahminator/pipeline 1.0.76-beta.0f9c2cb9 → 1.0.76-beta.4076a21f

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
@@ -194,6 +194,7 @@ await protobuf.compile({
194
194
  backend: {
195
195
  type: ProtobufCompilerBackend.ARTIFACT_KEEPER,
196
196
  token: process.env.ARTIFACT_KEEPER_TOKEN!,
197
+ url: process.env.ARTIFACT_KEEPER_URL!,
197
198
  username: process.env.ARTIFACT_KEEPER_USERNAME!,
198
199
  },
199
200
  sourceLanguage: ProtobufSourceLanguage.RUST,
@@ -391,6 +392,7 @@ Utilities to compute the next semver tag from GitHub and update versions in code
391
392
  ```ts
392
393
  const gh = await GitHubClient.createWithDefaultCiToken();
393
394
 
395
+ // available strategies: JSTS, JAVA_MAVEN, RUST_CARGO, NONE
394
396
  const versioning = new VersioningClient(gh, VersionUpdatingStrategy.JSTS);
395
397
 
396
398
  // if your repo has no tags yet, this will return `1.0.0`
@@ -1,12 +1,9 @@
1
- import { type ProtobufArtifactKeeperBackend, type ProtobufTargetLanguageOptions, ProtobufTargetLanguage } from "../types";
2
- export declare class ArtifactKeeperProtobufCompilerBackend {
1
+ import type { IProtobufCompilerBackendStrategy, ProtobufCompilerBackendPublishArgs } from "./types";
2
+ import { type ProtobufArtifactKeeperBackend } from "../types";
3
+ export declare class ArtifactKeeperProtobufCompilerBackend implements IProtobufCompilerBackendStrategy {
3
4
  private readonly config;
4
5
  constructor(config: ProtobufArtifactKeeperBackend);
5
- publish({ generatedDirectory, targetLanguage, options, }: {
6
- generatedDirectory: string;
7
- targetLanguage: ProtobufTargetLanguage;
8
- options: ProtobufTargetLanguageOptions;
9
- }): Promise<void>;
6
+ publish({ generatedDirectory, targetLanguage, options, }: ProtobufCompilerBackendPublishArgs): Promise<void>;
10
7
  private publishJava;
11
8
  private publishMaven;
12
9
  private publishGradle;
@@ -3,7 +3,6 @@ import { mkdir, mkdtemp, readdir, rename, rm, writeFile, } from "node:fs/promise
3
3
  import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
  import { ProtobufTargetLanguage, } from "../types";
6
- const DEFAULT_ARTIFACT_KEEPER_URL = "https://pkg.vpn.patinanetwork.org";
7
6
  const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
8
7
  const DEFAULT_PROST_VERSION = "0.14";
9
8
  export class ArtifactKeeperProtobufCompilerBackend {
@@ -223,7 +222,7 @@ prost = "${prostVersion}"
223
222
  });
224
223
  }
225
224
  get artifactKeeperUrl() {
226
- return (this.config.url ?? DEFAULT_ARTIFACT_KEEPER_URL).replace(/\/$/, "");
225
+ return this.config.url.replace(/\/$/, "");
227
226
  }
228
227
  get mavenRepositoryUrl() {
229
228
  return `${this.artifactKeeperUrl}/maven/maven/`;
@@ -1 +1,5 @@
1
+ import type { IProtobufCompilerBackendStrategy } from "./types";
2
+ import { type ProtobufCompilerBackendConfig } from "../types";
1
3
  export * from "./artifact-keeper";
4
+ export * from "./types";
5
+ export declare function createProtobufCompilerBackendStrategy(backend: ProtobufCompilerBackendConfig): IProtobufCompilerBackendStrategy;
@@ -1 +1,10 @@
1
+ import { ProtobufCompilerBackend, } from "../types";
2
+ import { ArtifactKeeperProtobufCompilerBackend } from "./artifact-keeper";
1
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
@@ -5,7 +5,6 @@ export declare class ProtobufCompilerClient {
5
5
  private generateWithBuf;
6
6
  private getCompilationTargets;
7
7
  private getConfiguredTargetLanguages;
8
- private getTargetLanguageStrategy;
9
8
  private getBufGenerateInput;
10
9
  private findBufModuleDirectory;
11
10
  }
@@ -4,16 +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 { ArtifactKeeperProtobufCompilerBackend } from "./backend";
7
+ import { createProtobufCompilerBackendStrategy } from "./backend";
8
8
  import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
9
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
+ };
10
15
  export class ProtobufCompilerClient {
11
16
  async compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
12
17
  await this.installToolchains();
13
18
  const outputDirectoryPath = path.resolve(outputDirectory ??
14
19
  (await mkdtemp(path.join(tmpdir(), "protobuf-compiler-"))));
15
20
  const targets = this.getCompilationTargets(targetLanguages);
16
- const artifactKeeper = backend ? new ArtifactKeeperProtobufCompilerBackend(backend) : undefined;
21
+ const compilerBackend = backend ? createProtobufCompilerBackendStrategy(backend) : undefined;
17
22
  await mkdir(outputDirectoryPath, { recursive: true });
18
23
  await this.generateWithBuf({
19
24
  bufToken,
@@ -25,13 +30,13 @@ export class ProtobufCompilerClient {
25
30
  for (const { language, strategy } of targets) {
26
31
  generatedDirectories[language] = path.join(outputDirectoryPath, strategy.outputDirectoryName);
27
32
  }
28
- if (artifactKeeper) {
33
+ if (compilerBackend) {
29
34
  for (const { language, options } of targets) {
30
35
  const generatedDirectory = generatedDirectories[language];
31
36
  if (!generatedDirectory) {
32
37
  throw new Error("Generated code directory was not created.");
33
38
  }
34
- await artifactKeeper.publish({
39
+ await compilerBackend.publish({
35
40
  generatedDirectory,
36
41
  options,
37
42
  targetLanguage: language,
@@ -75,27 +80,11 @@ export class ProtobufCompilerClient {
75
80
  return this.getConfiguredTargetLanguages(targetLanguages).map(([language, options]) => ({
76
81
  language,
77
82
  options,
78
- strategy: this.getTargetLanguageStrategy(language),
83
+ strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](),
79
84
  }));
80
85
  }
81
86
  getConfiguredTargetLanguages(targetLanguages) {
82
- const targets = [];
83
- for (const [language, options] of Object.entries(targetLanguages)) {
84
- if (!options)
85
- continue;
86
- targets.push([Number(language), options]);
87
- }
88
- return targets;
89
- }
90
- getTargetLanguageStrategy(targetLanguage) {
91
- switch (targetLanguage) {
92
- case ProtobufTargetLanguage.JAVA:
93
- return new JavaProtobufTargetLanguageStrategy();
94
- case ProtobufTargetLanguage.GO:
95
- return new GoProtobufTargetLanguageStrategy();
96
- case ProtobufTargetLanguage.RUST:
97
- return new RustProtobufTargetLanguageStrategy();
98
- }
87
+ return Object.entries(targetLanguages).flatMap(([language, options]) => options ? [[Number(language), options]] : []);
99
88
  }
100
89
  async getBufGenerateInput(protoFilesLocation) {
101
90
  const resolvedLocation = path.resolve(protoFilesLocation);
@@ -11,11 +11,11 @@ export declare enum ProtobufTargetLanguage {
11
11
  }
12
12
  export interface ProtobufArtifactKeeperBackend {
13
13
  type: ProtobufCompilerBackend.ARTIFACT_KEEPER;
14
- /** Defaults to `https://pkg.vpn.patinanetwork.org`. */
15
- url?: string;
14
+ url: string;
16
15
  username: string;
17
16
  token: string;
18
17
  }
18
+ export type ProtobufCompilerBackendConfig = ProtobufArtifactKeeperBackend;
19
19
  export interface ProtobufJavaTargetLanguageOptions {
20
20
  groupId: string;
21
21
  artifactId: string;
@@ -40,7 +40,7 @@ export type ProtobufTargetLanguages = {
40
40
  };
41
41
  export interface ProtobufCompilerCompileArgs {
42
42
  /** All targets are published through this one backend. */
43
- backend?: ProtobufArtifactKeeperBackend;
43
+ backend?: ProtobufCompilerBackendConfig;
44
44
  sourceLanguage: ProtobufSourceLanguage;
45
45
  /** Optional BSR API token used for Buf remote plugins. */
46
46
  bufToken?: string;
@@ -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.0f9c2cb9",
6
+ "version": "1.0.76-beta.4076a21f",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },