@tahminator/pipeline 1.0.78-beta.3ef6aac5 → 1.0.78

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
@@ -185,7 +185,7 @@ await client.promoteDockerImage({
185
185
 
186
186
  ### `ProtobufCompilerClient`
187
187
 
188
- Generate protobuf clients with the [Buf CLI](https://buf.build/docs/installation/) and its remote plugins. Java, Rust, and Go targets can be published to Artifact Keeper with Maven/Gradle, Cargo, or Go module uploads. 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.
189
189
 
190
190
  ```ts
191
191
  const protobuf = new ProtobufCompilerClient();
@@ -210,32 +210,6 @@ await protobuf.compile({
210
210
  });
211
211
  ```
212
212
 
213
- Configure generated-code packages in each `.proto` file, not in `targetLanguages`. The client does not enable Buf managed mode; Buf's generators read these file options directly:
214
-
215
- ```proto
216
- option go_package = "example.com/proto/helloworld/v1;helloworldv1";
217
- option java_package = "org.myorg.helloworld.v1";
218
- option java_multiple_files = true;
219
- ```
220
-
221
- `go_package` is required for Go generation with this client. Java package options are recommended; `java_outer_classname` is optional. Rust generation needs no language-specific file options. CI target options such as Java `groupId`/`artifactId` and Rust `crateName` are publishing metadata, not generated-code package names. Go's former unused `modulePath` option has been removed.
222
-
223
- For Go publishing, only the release version is needed:
224
-
225
- ```ts
226
- targetLanguages: {
227
- [ProtobufTargetLanguage.GO]: {
228
- version: "1.0.0",
229
- },
230
- },
231
- ```
232
-
233
- The publisher generates `go.mod` using the deepest shared directory of the generated Go packages as the module root. For a single package, that package's import path becomes the module path. It never adds, strips, or rewrites version suffixes. Proto authors own package layout; invalid Go module/version combinations fail. In particular, Go does not allow a module path ending in `/v1`. Adding packages outside the existing shared directory changes the inferred module root, so keep the package layout stable across releases.
234
-
235
- Go publishing requires `go` and `zip` on PATH. It stages generated packages without changing the original output, runs `go mod init` and `go mod tidy` to generate dependency metadata, and uploads `.mod` and `.zip` artifacts to the hosted `go` repository at `<backend.url>/go/go`. It does not lint, build, or test generated code. Dependency resolution may require network access. Versions may include a leading `v`; v2+ modules require the corresponding major-version module path suffix.
236
-
237
- Java generation is pinned to the compiler release matching `protobufJavaVersion` (default runtime `4.32.1`, Buf Java plugin `v32.1`). The same runtime version is used in both Maven and Gradle metadata. Overrides must be exact stable versions, not ranges, and the corresponding plugin must exist in the Buf registry.
238
-
239
213
  ### `NPMClient`
240
214
 
241
215
  Interface with NPM registry in order to publish packages to `npmjs.com`
@@ -3,8 +3,7 @@ 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
- import { DEFAULT_PROTOBUF_JAVA_VERSION } from "../versions";
7
- import { ArtifactKeeperGoPublisher } from "./go";
6
+ const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
8
7
  const DEFAULT_PROST_VERSION = "0.14";
9
8
  export class ArtifactKeeperProtobufCompilerBackend {
10
9
  config;
@@ -26,11 +25,7 @@ export class ArtifactKeeperProtobufCompilerBackend {
26
25
  });
27
26
  return;
28
27
  case ProtobufTargetLanguage.GO:
29
- await new ArtifactKeeperGoPublisher(this.config).publish({
30
- generatedDirectory,
31
- options: options,
32
- });
33
- return;
28
+ throw new Error("Artifact Keeper Go module publishing requires its upload workflow; only Go module consumption has been configured.");
34
29
  }
35
30
  }
36
31
  async publishJava({ generatedDirectory, options, }) {
@@ -67,12 +62,7 @@ export class ArtifactKeeperProtobufCompilerBackend {
67
62
  writeFile(path.join(generatedDirectory, "Cargo.toml"), this.createCargoToml(options)),
68
63
  writeFile(path.join(generatedDirectory, "src", "lib.rs"), this.createRustLibrary(generatedFiles)),
69
64
  ]);
70
- await $.env({
71
- ...process.env,
72
- CARGO_REGISTRIES_CARGO_INDEX: this.cargoIndexUrl,
73
- CARGO_REGISTRIES_CARGO_TOKEN: this.config.token,
74
- CARGO_REGISTRIES_CARGO_CREDENTIAL_PROVIDER: "cargo:token",
75
- }) `cargo publish --registry cargo`.cwd(generatedDirectory);
65
+ await $ `cargo publish --registry cargo --token ${this.config.token} --config ${`registries.cargo.index=${this.cargoIndexUrl}`}`.cwd(generatedDirectory);
76
66
  }
77
67
  async moveJavaSources(generatedDirectory) {
78
68
  const sourceDirectory = path.join(generatedDirectory, "src", "main", "java");
@@ -238,6 +228,6 @@ prost = "${prostVersion}"
238
228
  return `${this.artifactKeeperUrl}/maven/maven/`;
239
229
  }
240
230
  get cargoIndexUrl() {
241
- return `sparse+${this.artifactKeeperUrl}/cargo/cargo/`;
231
+ return `${this.artifactKeeperUrl}/cargo/cargo/index`;
242
232
  }
243
233
  }
@@ -8,7 +8,7 @@ import { createProtobufCompilerBackendStrategy } from "./backend";
8
8
  import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
9
9
  import { ProtobufTargetLanguage, } from "./types";
10
10
  const TARGET_LANGUAGE_STRATEGY_FACTORIES = {
11
- [ProtobufTargetLanguage.JAVA]: (targets) => new JavaProtobufTargetLanguageStrategy(targets[ProtobufTargetLanguage.JAVA]?.protobufJavaVersion),
11
+ [ProtobufTargetLanguage.JAVA]: () => new JavaProtobufTargetLanguageStrategy(),
12
12
  [ProtobufTargetLanguage.GO]: () => new GoProtobufTargetLanguageStrategy(),
13
13
  [ProtobufTargetLanguage.RUST]: () => new RustProtobufTargetLanguageStrategy(),
14
14
  };
@@ -80,7 +80,7 @@ export class ProtobufCompilerClient {
80
80
  return this.getConfiguredTargetLanguages(targetLanguages).map(([language, options]) => ({
81
81
  language,
82
82
  options,
83
- strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](targetLanguages),
83
+ strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](),
84
84
  }));
85
85
  }
86
86
  getConfiguredTargetLanguages(targetLanguages) {
@@ -1,6 +1,5 @@
1
1
  import type { IProtobufTargetLanguageStrategy } from "./types";
2
2
  export declare class JavaProtobufTargetLanguageStrategy implements IProtobufTargetLanguageStrategy {
3
3
  readonly outputDirectoryName = "java";
4
- readonly remotePlugin: string;
5
- constructor(runtimeVersion?: string);
4
+ readonly remotePlugin = "buf.build/protocolbuffers/java";
6
5
  }
@@ -1,8 +1,4 @@
1
- import { DEFAULT_PROTOBUF_JAVA_VERSION, javaGeneratorVersion, } from "../versions";
2
1
  export class JavaProtobufTargetLanguageStrategy {
3
2
  outputDirectoryName = "java";
4
- remotePlugin;
5
- constructor(runtimeVersion = DEFAULT_PROTOBUF_JAVA_VERSION) {
6
- this.remotePlugin = `buf.build/protocolbuffers/java:v${javaGeneratorVersion(runtimeVersion)}`;
7
- }
3
+ remotePlugin = "buf.build/protocolbuffers/java";
8
4
  }
@@ -17,12 +17,10 @@ export interface ProtobufArtifactKeeperBackend {
17
17
  }
18
18
  export type ProtobufCompilerBackendConfig = ProtobufArtifactKeeperBackend;
19
19
  export interface ProtobufJavaTargetLanguageOptions {
20
- /** Maven/Gradle publishing group; Java packages are configured in .proto files. */
21
20
  groupId: string;
22
21
  artifactId: string;
23
22
  version: string;
24
23
  buildTool?: "maven" | "gradle";
25
- /** Exact stable Java runtime version; also pins the matching Buf generator. Defaults to 4.32.1. */
26
24
  protobufJavaVersion?: string;
27
25
  }
28
26
  export interface ProtobufRustTargetLanguageOptions {
@@ -30,8 +28,8 @@ export interface ProtobufRustTargetLanguageOptions {
30
28
  version: string;
31
29
  prostVersion?: string;
32
30
  }
33
- /** Go import paths are configured with go_package in .proto files. */
34
31
  export interface ProtobufGoTargetLanguageOptions {
32
+ modulePath: string;
35
33
  version: string;
36
34
  }
37
35
  export type ProtobufTargetLanguageOptions = ProtobufGoTargetLanguageOptions | ProtobufJavaTargetLanguageOptions | ProtobufRustTargetLanguageOptions;
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.78-beta.3ef6aac5",
6
+ "version": "1.0.78",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -1,22 +0,0 @@
1
- import type { ProtobufArtifactKeeperBackend, ProtobufGoTargetLanguageOptions } from "../types";
2
- /** Publishes Buf's import-path output as a hosted Go proxy module. */
3
- export declare class ArtifactKeeperGoPublisher {
4
- private readonly config;
5
- constructor(config: ProtobufArtifactKeeperBackend);
6
- publish({ generatedDirectory, options, }: {
7
- generatedDirectory: string;
8
- options: ProtobufGoTargetLanguageOptions;
9
- }): Promise<void>;
10
- private normalizeVersion;
11
- private requireToolchains;
12
- private inferModulePath;
13
- private findPackageDirectories;
14
- private validateModuleVersion;
15
- private stageModule;
16
- private packageModule;
17
- private uploadArtifact;
18
- private archiveRoot;
19
- private escapeProxyPath;
20
- private get repositoryUrl();
21
- private get shell();
22
- }
@@ -1,149 +0,0 @@
1
- import { $ } from "bun";
2
- import { cp, mkdir, mkdtemp, readdir, rm } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import path from "node:path";
5
- import semver from "semver";
6
- import { isCmdAvailable } from "../../utils/cmd";
7
- /** Publishes Buf's import-path output as a hosted Go proxy module. */
8
- export class ArtifactKeeperGoPublisher {
9
- config;
10
- constructor(config) {
11
- this.config = config;
12
- }
13
- async publish({ generatedDirectory, options, }) {
14
- const version = this.normalizeVersion(options.version);
15
- await this.requireToolchains();
16
- const modulePath = await this.inferModulePath(generatedDirectory);
17
- this.validateModuleVersion(modulePath, version);
18
- const module = { modulePath, version };
19
- const stagingDirectory = await mkdtemp(path.join(tmpdir(), "protobuf-go-"));
20
- try {
21
- const moduleDirectory = await this.stageModule(module, generatedDirectory, stagingDirectory);
22
- const artifacts = await this.packageModule(module, moduleDirectory, stagingDirectory);
23
- for (const artifact of artifacts) {
24
- await this.uploadArtifact(module, artifact);
25
- }
26
- }
27
- finally {
28
- await rm(stagingDirectory, { force: true, recursive: true });
29
- }
30
- }
31
- normalizeVersion(value) {
32
- const version = `v${value.replace(/^v/, "")}`;
33
- if (!semver.valid(version) || version.includes("+")) {
34
- throw new Error("Go publishing requires a semantic version without build metadata.");
35
- }
36
- return version;
37
- }
38
- async requireToolchains() {
39
- for (const command of ["go", "zip"]) {
40
- if (!(await isCmdAvailable(command))) {
41
- throw new Error(`Go publishing requires ${command} on PATH.`);
42
- }
43
- }
44
- }
45
- async inferModulePath(generatedDirectory) {
46
- const packages = await this.findPackageDirectories(generatedDirectory);
47
- const prefix = packages[0]?.split("/") ?? [];
48
- for (const directory of packages.slice(1)) {
49
- const segments = directory.split("/");
50
- while (prefix.some((segment, index) => segment !== segments[index])) {
51
- prefix.pop();
52
- }
53
- }
54
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
- if (prefix.length < 2 || !prefix[0].includes(".")) {
56
- throw new Error("Generated go_package paths must share a module prefix containing a domain and path.");
57
- }
58
- return prefix.join("/");
59
- }
60
- async findPackageDirectories(directory, relativeDirectory = "") {
61
- const entries = await readdir(directory, { withFileTypes: true });
62
- const packages = [];
63
- if (entries.some((entry) => entry.isFile() && entry.name.endsWith(".go"))) {
64
- packages.push(relativeDirectory);
65
- }
66
- for (const entry of entries) {
67
- if (entry.isDirectory()) {
68
- packages.push(...(await this.findPackageDirectories(path.join(directory, entry.name), relativeDirectory ?
69
- `${relativeDirectory}/${entry.name}`
70
- : entry.name)));
71
- }
72
- }
73
- return packages;
74
- }
75
- validateModuleVersion(modulePath, version) {
76
- const major = semver.major(version);
77
- const pathMajor = modulePath.match(/\/v([0-9]+)$/)?.[1] ??
78
- (modulePath.startsWith("gopkg.in/") ?
79
- modulePath.match(/\.v([0-9]+)$/)?.[1]
80
- : undefined);
81
- if ((pathMajor &&
82
- !modulePath.startsWith("gopkg.in/") &&
83
- Number(pathMajor) < 2) ||
84
- (pathMajor && Number(pathMajor) !== major) ||
85
- (!pathMajor && major >= 2)) {
86
- throw new Error(`Go module path ${modulePath} does not match version ${version}.`);
87
- }
88
- }
89
- async stageModule(module, generatedDirectory, stagingDirectory) {
90
- // Buf's default paths=import layout includes the full go_package import path.
91
- // Strip only the module prefix, without modifying the original output.
92
- const sourceDirectory = path.join(generatedDirectory, module.modulePath);
93
- const moduleDirectory = path.join(stagingDirectory, this.archiveRoot(module));
94
- await mkdir(path.dirname(moduleDirectory), { recursive: true });
95
- await cp(sourceDirectory, moduleDirectory, { recursive: true });
96
- await this.shell `go mod init ${module.modulePath}`.cwd(moduleDirectory);
97
- return moduleDirectory;
98
- }
99
- async packageModule(module, moduleDirectory, stagingDirectory) {
100
- // Resolve dependency metadata; generated code is not linted or tested.
101
- await this.shell `go mod tidy`.cwd(moduleDirectory);
102
- const archivePath = path.join(stagingDirectory, "module.zip");
103
- const archiveRoot = this.archiveRoot(module);
104
- await this
105
- .shell `zip -q -r ${archivePath} ${archiveRoot} -i ${`${archiveRoot}/*`}`.cwd(stagingDirectory);
106
- return [
107
- {
108
- extension: "mod",
109
- filePath: path.join(moduleDirectory, "go.mod"),
110
- contentType: "text/plain",
111
- },
112
- {
113
- extension: "zip",
114
- filePath: archivePath,
115
- contentType: "application/zip",
116
- },
117
- ];
118
- }
119
- async uploadArtifact(module, artifact) {
120
- const url = `${this.repositoryUrl}/${this.escapeProxyPath(module.modulePath)}/@v/${this.escapeProxyPath(module.version)}.${artifact.extension}`;
121
- const credentials = Buffer.from(`${this.config.username}:${this.config.token}`).toString("base64");
122
- const response = await fetch(url, {
123
- method: "PUT",
124
- headers: {
125
- Authorization: `Basic ${credentials}`,
126
- "Content-Type": artifact.contentType,
127
- },
128
- body: Bun.file(artifact.filePath),
129
- redirect: "error",
130
- });
131
- await response.body?.cancel();
132
- if (!response.ok) {
133
- throw new Error(`Go ${artifact.extension} upload failed: HTTP ${response.status}`);
134
- }
135
- }
136
- archiveRoot(module) {
137
- return `${module.modulePath}@${module.version}`;
138
- }
139
- escapeProxyPath(value) {
140
- // Go proxy URLs escape uppercase letters; archive entries do not.
141
- return value.replace(/[A-Z]/g, (letter) => `!${letter.toLowerCase()}`);
142
- }
143
- get repositoryUrl() {
144
- return `${this.config.url.replace(/\/$/, "")}/go/go`;
145
- }
146
- get shell() {
147
- return $.env({ ...process.env, GOWORK: "off" });
148
- }
149
- }
@@ -1,3 +0,0 @@
1
- export declare const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
2
- /** Java runtime releases include a language major absent from modern protoc tags. */
3
- export declare function javaGeneratorVersion(runtimeVersion: string): string;
@@ -1,13 +0,0 @@
1
- export const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
2
- /** Java runtime releases include a language major absent from modern protoc tags. */
3
- export function javaGeneratorVersion(runtimeVersion) {
4
- const match = /^(3|4)\.(\d+)\.(\d+)$/.exec(runtimeVersion);
5
- if (!match) {
6
- throw new Error("protobufJavaVersion must be an exact stable 3.x or 4.x version.");
7
- }
8
- const [, major, minor, patch] = match;
9
- // Before protoc 21, compiler and Java runtime used the same 3.x version.
10
- return major === "3" && Number(minor) < 21 ?
11
- runtimeVersion
12
- : `${minor}.${patch}`;
13
- }