@tahminator/pipeline 1.0.53 → 1.0.55-beta.46bb197d

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/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./pulumi";
6
6
  export * from "./types";
7
7
  export * from "./env";
8
8
  export * from "./utils";
9
+ export * from "./versioning";
package/dist/index.js CHANGED
@@ -6,3 +6,4 @@ export * from "./pulumi";
6
6
  export * from "./types";
7
7
  export * from "./env";
8
8
  export * from "./utils";
9
+ export * from "./versioning";
@@ -4,6 +4,8 @@ import { EnvClient, EnvClientStrategy } from "../../../env";
4
4
  import { GitHubClient } from "../../../gh";
5
5
  import { NPMClient } from "../../../npm";
6
6
  import { Utils } from "../../../utils";
7
+ import { VersioningClient } from "../../../versioning";
8
+ import { VersioningStrategy } from "../../../versioning/types";
7
9
  const { sha, prId } = await yargs(hideBin(process.argv))
8
10
  .option("sha", {
9
11
  type: "string",
@@ -24,13 +26,14 @@ async function main() {
24
26
  privateKey: await Utils.decodeBase64EncodedString(githubAppPrivateKeyB64),
25
27
  });
26
28
  const npmClient = await NPMClient.create();
29
+ const versioningClient = new VersioningClient(VersioningStrategy.JSTS);
27
30
  const shortSha = await getShortSha(sha);
28
31
  const lastTag = (await ghClient.getLatestTag()) ?? GitHubClient.BASE_VERSION;
29
32
  const betaVersion = `${lastTag}-beta.${shortSha}`;
30
33
  if (!Utils.SemVer.validate(betaVersion)) {
31
34
  throw new Error(`Generated invalid beta version: ${betaVersion}`);
32
35
  }
33
- await Utils.updateAllPackageJsonsWithVersion(betaVersion);
36
+ await versioningClient.update(betaVersion);
34
37
  await npmClient.publish(false, true);
35
38
  console.log(`Uploaded ${betaVersion} to NPM.`);
36
39
  await ghClient.sendPrMessage({
@@ -40,7 +43,7 @@ async function main() {
40
43
  message: `
41
44
  ## Test Version Uploaded
42
45
 
43
- Uploaded ${betaVersion} to NPM. View version on NPM registry [here](https://www.npmjs.com/package/@tahminator/pipeline/v/${betaVersion}).
46
+ Uploaded \`${betaVersion}\` to NPM. View version on NPM registry [here](https://www.npmjs.com/package/@tahminator/pipeline/v/${betaVersion}).
44
47
  `,
45
48
  });
46
49
  }
@@ -45,10 +45,14 @@ export class LocalWorkspacePulumiClientStrategy {
45
45
  return line;
46
46
  }
47
47
  const trimmed = line.trimStart();
48
- const symbol = trimmed.startsWith("+-") ? "!"
49
- : trimmed.startsWith("+") ? "+"
50
- : trimmed.startsWith("-") ? "-"
51
- : trimmed.startsWith("~") ? "!"
48
+ const symbol = trimmed.startsWith("+-") ?
49
+ "-" // replace
50
+ : trimmed.startsWith("+") ?
51
+ "+" // create
52
+ : trimmed.startsWith("-") ?
53
+ "-" // delete
54
+ : trimmed.startsWith("~") ?
55
+ "!" // modify
52
56
  : null;
53
57
  if (!symbol) {
54
58
  return line;
@@ -9,7 +9,6 @@ export declare class Utils {
9
9
  static Log: typeof Log;
10
10
  static SemVer: typeof SemVer;
11
11
  static generateShortId(...args: Parameters<typeof generateShortId>): string;
12
- static updateAllPackageJsonsWithVersion(version: string): Promise<void>;
13
12
  static isCmdAvailable(...args: Parameters<typeof isCmdAvailable>): Promise<boolean>;
14
13
  static decodeBase64EncodedString(...args: Parameters<typeof decodeBase64EncodedString>): Promise<string>;
15
14
  }
@@ -1,4 +1,3 @@
1
- import { $ } from "bun";
2
1
  import { decodeBase64EncodedString } from "./b64";
3
2
  import { isCmdAvailable } from "./cmd";
4
3
  import { Colors } from "./colors";
@@ -13,18 +12,6 @@ export class Utils {
13
12
  static generateShortId(...args) {
14
13
  return generateShortId(...args);
15
14
  }
16
- static async updateAllPackageJsonsWithVersion(version) {
17
- const files = (await $ `find . -name "package.json" -not -path "*/node_modules/*"`.text())
18
- .trim()
19
- .split("\n");
20
- for (const fileLocation of files) {
21
- const file = Bun.file(fileLocation);
22
- const pkg = await file.json();
23
- pkg.version = version;
24
- await Bun.write(fileLocation, JSON.stringify(pkg, null, 2) + "\n");
25
- console.log(`Successfully updated version in ${fileLocation} to ${version}`);
26
- }
27
- }
28
15
  static async isCmdAvailable(...args) {
29
16
  return isCmdAvailable(...args);
30
17
  }
@@ -0,0 +1,6 @@
1
+ import type { IVersioningClient } from "./types";
2
+ export declare abstract class BaseVersioningClient implements IVersioningClient {
3
+ abstract update(version: string): Promise<void>;
4
+ protected logFileLocationUpdated(fileLocation: string, version: string): void;
5
+ protected findFiles(filePattern: string, pathExclusionRegex?: RegExp): Promise<string[]>;
6
+ }
@@ -0,0 +1,16 @@
1
+ export class BaseVersioningClient {
2
+ logFileLocationUpdated(fileLocation, version) {
3
+ console.log(`Successfully updated version in ${fileLocation} to ${version}`);
4
+ }
5
+ async findFiles(filePattern, pathExclusionRegex) {
6
+ const glob = new Bun.Glob(filePattern);
7
+ const files = [];
8
+ for await (const file of glob.scan(".")) {
9
+ if (pathExclusionRegex && pathExclusionRegex.test(file)) {
10
+ continue;
11
+ }
12
+ files.push(file);
13
+ }
14
+ return files;
15
+ }
16
+ }
@@ -0,0 +1,7 @@
1
+ import { VersioningStrategy, type IVersioningClient } from "./types";
2
+ export declare class VersioningClient implements IVersioningClient {
3
+ private readonly delegate;
4
+ constructor(strategy: VersioningStrategy);
5
+ private getDelegate;
6
+ update(version: string): Promise<void>;
7
+ }
@@ -0,0 +1,20 @@
1
+ import { JavaMavenVersioningClient } from "./java/maven";
2
+ import { JavascriptPackageJsonVersioningClient } from "./jsts";
3
+ import { VersioningStrategy } from "./types";
4
+ export class VersioningClient {
5
+ delegate;
6
+ constructor(strategy) {
7
+ this.delegate = this.getDelegate(strategy);
8
+ }
9
+ getDelegate(strategy) {
10
+ switch (strategy) {
11
+ case VersioningStrategy.JSTS:
12
+ return new JavascriptPackageJsonVersioningClient();
13
+ case VersioningStrategy.JAVA_MAVEN:
14
+ return new JavaMavenVersioningClient();
15
+ }
16
+ }
17
+ async update(version) {
18
+ await this.delegate.update(version);
19
+ }
20
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./types";
@@ -0,0 +1,8 @@
1
+ import type { IJavaMavenVersioningClient } from "../../types";
2
+ import { BaseVersioningClient } from "../../base";
3
+ export declare class JavaMavenVersioningClient extends BaseVersioningClient implements IJavaMavenVersioningClient {
4
+ private readonly parser;
5
+ private readonly builder;
6
+ constructor();
7
+ update(version: string): Promise<void>;
8
+ }
@@ -0,0 +1,39 @@
1
+ import XMLBuilderClient, {} from "fast-xml-builder";
2
+ import { XMLParser } from "fast-xml-parser";
3
+ import { BaseVersioningClient } from "../../base";
4
+ export class JavaMavenVersioningClient extends BaseVersioningClient {
5
+ parser;
6
+ builder;
7
+ constructor() {
8
+ super();
9
+ this.parser = new XMLParser({
10
+ ignoreAttributes: false,
11
+ preserveOrder: true,
12
+ attributeNamePrefix: "@_",
13
+ allowBooleanAttributes: true,
14
+ });
15
+ this.builder = new XMLBuilderClient({
16
+ ignoreAttributes: false,
17
+ preserveOrder: true,
18
+ attributeNamePrefix: "@_",
19
+ });
20
+ }
21
+ async update(version) {
22
+ const files = await this.findFiles("pom.xml");
23
+ for (const fileLocation of files) {
24
+ const file = Bun.file(fileLocation);
25
+ const oldPomStr = await file.text();
26
+ const pom = this.parser.parse(oldPomStr);
27
+ if (!pom.project) {
28
+ throw new Error("Can't find project tag inside of pom.xml");
29
+ }
30
+ if (!pom.project.version) {
31
+ throw new Error("Can't find version tag inside of project tag in pom.xml");
32
+ }
33
+ pom.project.version = version;
34
+ const newPomStr = this.builder.build(pom);
35
+ await Bun.write(fileLocation, newPomStr);
36
+ this.logFileLocationUpdated(fileLocation, version);
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ import type { IJavascriptPackageJsonVersioningClient } from "../types";
2
+ import { BaseVersioningClient } from "../base";
3
+ export declare class JavascriptPackageJsonVersioningClient extends BaseVersioningClient implements IJavascriptPackageJsonVersioningClient {
4
+ update(version: string): Promise<void>;
5
+ }
@@ -0,0 +1,13 @@
1
+ import { BaseVersioningClient } from "../base";
2
+ export class JavascriptPackageJsonVersioningClient extends BaseVersioningClient {
3
+ async update(version) {
4
+ const files = await this.findFiles("**/package.json", /(^|\/)node_modules\//);
5
+ for (const fileLocation of files) {
6
+ const file = Bun.file(fileLocation);
7
+ const pkg = await file.json();
8
+ pkg.version = version;
9
+ await Bun.write(fileLocation, JSON.stringify(pkg, null, 2) + "\n");
10
+ this.logFileLocationUpdated(fileLocation, version);
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,11 @@
1
+ export declare enum VersioningStrategy {
2
+ JSTS = 0,
3
+ JAVA_MAVEN = 1
4
+ }
5
+ export interface IVersioningClient {
6
+ update(version: string): Promise<void>;
7
+ }
8
+ export interface IJavascriptPackageJsonVersioningClient extends IVersioningClient {
9
+ }
10
+ export interface IJavaMavenVersioningClient extends IVersioningClient {
11
+ }
@@ -0,0 +1,5 @@
1
+ export var VersioningStrategy;
2
+ (function (VersioningStrategy) {
3
+ VersioningStrategy[VersioningStrategy["JSTS"] = 0] = "JSTS";
4
+ VersioningStrategy[VersioningStrategy["JAVA_MAVEN"] = 1] = "JAVA_MAVEN";
5
+ })(VersioningStrategy || (VersioningStrategy = {}));
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.53",
6
+ "version": "1.0.55-beta.46bb197d",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -52,6 +52,8 @@
52
52
  "@octokit/rest": "^22.0.1",
53
53
  "@pulumi/pulumi": "^3.230.0",
54
54
  "ansi-to-html": "^0.7.2",
55
+ "fast-xml-builder": "^1.1.5",
56
+ "fast-xml-parser": "^5.7.2",
55
57
  "neverthrow": "^8.2.0",
56
58
  "semver": "^7.7.4",
57
59
  "yaml": "^2.8.2",