@tahminator/pipeline 1.0.56 → 1.0.57

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.
@@ -5,7 +5,7 @@ import { GitHubClient } from "../../../gh";
5
5
  import { NPMClient } from "../../../npm";
6
6
  import { Utils } from "../../../utils";
7
7
  import { VersioningClient } from "../../../versioning";
8
- import { VersioningStrategy } from "../../../versioning/types";
8
+ import { VersionUpdatingStrategy } from "../../../versioning/types";
9
9
  const { sha, prId } = await yargs(hideBin(process.argv))
10
10
  .option("sha", {
11
11
  type: "string",
@@ -26,7 +26,7 @@ async function main() {
26
26
  privateKey: await Utils.decodeBase64EncodedString(githubAppPrivateKeyB64),
27
27
  });
28
28
  const npmClient = await NPMClient.create();
29
- const versioningClient = new VersioningClient(VersioningStrategy.JSTS);
29
+ const versioningClient = new VersioningClient(ghClient, VersionUpdatingStrategy.JSTS);
30
30
  const shortSha = await getShortSha(sha);
31
31
  const lastTag = (await ghClient.getLatestTag()) ?? GitHubClient.BASE_VERSION;
32
32
  const betaVersion = `${lastTag}-beta.${shortSha}`;
@@ -1,7 +1,26 @@
1
- import { VersioningStrategy, type IVersioningClient } from "./types";
1
+ import type { GitHubClient } from "../gh";
2
+ import { VersionUpdatingStrategy, type IVersioningClient } from "./types";
2
3
  export declare class VersioningClient implements IVersioningClient {
4
+ private readonly githubClient;
5
+ private static readonly INITIAL_VERSION;
3
6
  private readonly delegate;
4
- constructor(strategy: VersioningStrategy);
7
+ constructor(githubClient: GitHubClient, strategy: VersionUpdatingStrategy);
5
8
  private getDelegate;
9
+ private parseOrThrow;
6
10
  update(version: string): Promise<void>;
11
+ /**
12
+ * generate next version tag.
13
+ *
14
+ * If `baseVersion` is not passed in:
15
+ * - if the repository has no tags yet, it will return `1.0.0`
16
+ * - otherwise, it will bump the latest tag's patch number
17
+ *
18
+ * if `baseVersion` is passed in, it will consult the github client and do the following:
19
+ *
20
+ * - if the github client reports a latest tag with the same `MAJOR` and `MINOR` version as `baseVersion`, it will just bump `PATCH` number
21
+ * - if the github client reports a latest tag with a lower `MAJOR` and `MINOR` version than `baseVersion`, it will match `baseVersion`'s `MAJOR` & `MINOR`. __It will NOT bump `PATCH` number.__
22
+ *
23
+ * `baseVersion` must set patch number to `0`. (e.g. `1.0.0`, `1.5.0`, `2.0.0`, etc.)
24
+ */
25
+ next(baseVersion?: string, ...opts: Parameters<GitHubClient["getLatestTag"]>): Promise<string>;
7
26
  }
@@ -1,20 +1,70 @@
1
- import { JavaMavenVersioningClient } from "./java/maven";
2
- import { JavascriptPackageJsonVersioningClient } from "./jsts";
3
- import { VersioningStrategy } from "./types";
1
+ import semver from "semver";
2
+ import { VersionUpdatingStrategy, } from "./types";
3
+ import { JavaMavenVersioningClient } from "./updating/java/maven";
4
+ import { JavascriptPackageJsonVersioningClient } from "./updating/jsts";
4
5
  export class VersioningClient {
6
+ githubClient;
7
+ static INITIAL_VERSION = "1.0.0";
5
8
  delegate;
6
- constructor(strategy) {
9
+ constructor(githubClient, strategy) {
10
+ this.githubClient = githubClient;
7
11
  this.delegate = this.getDelegate(strategy);
8
12
  }
9
13
  getDelegate(strategy) {
10
14
  switch (strategy) {
11
- case VersioningStrategy.JSTS:
15
+ case VersionUpdatingStrategy.JSTS:
12
16
  return new JavascriptPackageJsonVersioningClient();
13
- case VersioningStrategy.JAVA_MAVEN:
17
+ case VersionUpdatingStrategy.JAVA_MAVEN:
14
18
  return new JavaMavenVersioningClient();
15
19
  }
16
20
  }
21
+ parseOrThrow(label, v) {
22
+ const s = semver.parse(v);
23
+ if (!s) {
24
+ throw new Error(`${label} is not valid semver`);
25
+ }
26
+ return s;
27
+ }
17
28
  async update(version) {
18
29
  await this.delegate.update(version);
19
30
  }
31
+ /**
32
+ * generate next version tag.
33
+ *
34
+ * If `baseVersion` is not passed in:
35
+ * - if the repository has no tags yet, it will return `1.0.0`
36
+ * - otherwise, it will bump the latest tag's patch number
37
+ *
38
+ * if `baseVersion` is passed in, it will consult the github client and do the following:
39
+ *
40
+ * - if the github client reports a latest tag with the same `MAJOR` and `MINOR` version as `baseVersion`, it will just bump `PATCH` number
41
+ * - if the github client reports a latest tag with a lower `MAJOR` and `MINOR` version than `baseVersion`, it will match `baseVersion`'s `MAJOR` & `MINOR`. __It will NOT bump `PATCH` number.__
42
+ *
43
+ * `baseVersion` must set patch number to `0`. (e.g. `1.0.0`, `1.5.0`, `2.0.0`, etc.)
44
+ */
45
+ async next(baseVersion, ...opts) {
46
+ const latestTag = await this.githubClient.getLatestTag(...opts);
47
+ if (!baseVersion) {
48
+ if (!latestTag) {
49
+ return VersioningClient.INITIAL_VERSION;
50
+ }
51
+ else {
52
+ const latestSemver = this.parseOrThrow("latest tag from github", latestTag);
53
+ return latestSemver.inc("patch").toString();
54
+ }
55
+ }
56
+ const baseVersionSemver = this.parseOrThrow("baseVersion", baseVersion);
57
+ if (baseVersionSemver.patch !== 0) {
58
+ throw new Error("baseVersion has a non-zero patch number.");
59
+ }
60
+ if (!latestTag) {
61
+ return baseVersionSemver.inc("patch").toString();
62
+ }
63
+ const latestSemver = this.parseOrThrow("latest tag from github", latestTag);
64
+ if (latestSemver.major === baseVersionSemver.major &&
65
+ latestSemver.minor === baseVersionSemver.minor) {
66
+ return latestSemver.inc("patch").toString();
67
+ }
68
+ return baseVersionSemver.toString();
69
+ }
20
70
  }
@@ -1,11 +1,28 @@
1
- export declare enum VersioningStrategy {
1
+ export declare enum VersionUpdatingStrategy {
2
2
  JSTS = 0,
3
3
  JAVA_MAVEN = 1
4
4
  }
5
- export interface IVersioningClient {
5
+ export interface IVersionUpdatingClient {
6
6
  update(version: string): Promise<void>;
7
7
  }
8
- export interface IJavascriptPackageJsonVersioningClient extends IVersioningClient {
8
+ export interface IVersioningClient extends IVersionUpdatingClient {
9
+ /**
10
+ * generate next version tag.
11
+ *
12
+ * If `baseVersion` is not passed in:
13
+ * - if the repository has no tags yet, it will return `1.0.0`
14
+ * - otherwise, it will bump the latest tag's patch number
15
+ *
16
+ * if `baseVersion` is passed in, it will consult the github client and do the following:
17
+ *
18
+ * - if the github client reports a latest tag with the same `MAJOR` and `MINOR` version as `baseVersion`, it will just bump `PATCH` number
19
+ * - if the github client reports a latest tag with a lower `MAJOR` and `MINOR` version than `baseVersion`, it will match `baseVersion`'s `MAJOR` & `MINOR`. __It will NOT bump `PATCH` number.__
20
+ *
21
+ * `baseVersion` must set patch number to `0`. (e.g. `1.0.0`, `1.5.0`, `2.0.0`, etc.)
22
+ */
23
+ next(baseVersion?: string): Promise<string>;
9
24
  }
10
- export interface IJavaMavenVersioningClient extends IVersioningClient {
25
+ export interface IJavascriptPackageJsonVersionUpdatingClient extends IVersionUpdatingClient {
26
+ }
27
+ export interface IJavaMavenVersionUpdatingClient extends IVersionUpdatingClient {
11
28
  }
@@ -1,5 +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 = {}));
1
+ export var VersionUpdatingStrategy;
2
+ (function (VersionUpdatingStrategy) {
3
+ VersionUpdatingStrategy[VersionUpdatingStrategy["JSTS"] = 0] = "JSTS";
4
+ VersionUpdatingStrategy[VersionUpdatingStrategy["JAVA_MAVEN"] = 1] = "JAVA_MAVEN";
5
+ })(VersionUpdatingStrategy || (VersionUpdatingStrategy = {}));
@@ -1,5 +1,5 @@
1
- import type { IVersioningClient } from "./types";
2
- export declare abstract class BaseVersioningClient implements IVersioningClient {
1
+ import type { IVersionUpdatingClient } from "../types";
2
+ export declare abstract class BaseVersionUpdatingClient implements IVersionUpdatingClient {
3
3
  abstract update(version: string): Promise<void>;
4
4
  protected logFileLocationUpdated(fileLocation: string, version: string): void;
5
5
  protected findFiles(filePattern: string, pathExclusionRegex?: RegExp): Promise<string[]>;
@@ -1,4 +1,4 @@
1
- export class BaseVersioningClient {
1
+ export class BaseVersionUpdatingClient {
2
2
  logFileLocationUpdated(fileLocation, version) {
3
3
  console.log(`Successfully updated version in ${fileLocation} to ${version}`);
4
4
  }
@@ -0,0 +1,6 @@
1
+ import type { IJavaMavenVersionUpdatingClient } from "../../../types";
2
+ import { BaseVersionUpdatingClient } from "../../base";
3
+ export declare class JavaMavenVersioningClient extends BaseVersionUpdatingClient implements IJavaMavenVersionUpdatingClient {
4
+ private getVersionNode;
5
+ update(version: string): Promise<void>;
6
+ }
@@ -1,6 +1,6 @@
1
1
  import { XmlElement, XmlParser, XmlText } from "xml-trueformat";
2
- import { BaseVersioningClient } from "../../base";
3
- export class JavaMavenVersioningClient extends BaseVersioningClient {
2
+ import { BaseVersionUpdatingClient } from "../../base";
3
+ export class JavaMavenVersioningClient extends BaseVersionUpdatingClient {
4
4
  getVersionNode(projectNode) {
5
5
  const versionNode = projectNode.children.find((child) => child instanceof XmlElement && child.tagName === "version");
6
6
  if (!versionNode) {
@@ -0,0 +1,5 @@
1
+ import type { IJavascriptPackageJsonVersionUpdatingClient } from "../../types";
2
+ import { BaseVersionUpdatingClient } from "../base";
3
+ export declare class JavascriptPackageJsonVersioningClient extends BaseVersionUpdatingClient implements IJavascriptPackageJsonVersionUpdatingClient {
4
+ update(version: string): Promise<void>;
5
+ }
@@ -1,5 +1,5 @@
1
- import { BaseVersioningClient } from "../base";
2
- export class JavascriptPackageJsonVersioningClient extends BaseVersioningClient {
1
+ import { BaseVersionUpdatingClient } from "../base";
2
+ export class JavascriptPackageJsonVersioningClient extends BaseVersionUpdatingClient {
3
3
  async update(version) {
4
4
  const files = await this.findFiles("**/package.json", /(^|\/)node_modules\//);
5
5
  for (const fileLocation of files) {
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.56",
6
+ "version": "1.0.57",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -1,6 +0,0 @@
1
- import type { IJavaMavenVersioningClient } from "../../types";
2
- import { BaseVersioningClient } from "../../base";
3
- export declare class JavaMavenVersioningClient extends BaseVersioningClient implements IJavaMavenVersioningClient {
4
- private getVersionNode;
5
- update(version: string): Promise<void>;
6
- }
@@ -1,5 +0,0 @@
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
- }