@tahminator/pipeline 1.0.56 → 1.0.58

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.
@@ -4,7 +4,6 @@ import { GitHubTagManager } from "./tag";
4
4
  export declare class GitHubClient {
5
5
  private readonly client;
6
6
  private readonly isExplicitToken;
7
- static readonly BASE_VERSION = "1.0.0";
8
7
  private readonly tagManager;
9
8
  private readonly outputManager;
10
9
  private readonly prManager;
package/dist/gh/client.js CHANGED
@@ -6,7 +6,6 @@ import { GitHubTagManager } from "./tag";
6
6
  export class GitHubClient {
7
7
  client;
8
8
  isExplicitToken;
9
- static BASE_VERSION = GitHubTagManager.BASE_VERSION;
10
9
  tagManager;
11
10
  outputManager;
12
11
  prManager;
@@ -1,10 +1,8 @@
1
1
  import { Octokit } from "@octokit/rest";
2
- import semver from "semver";
3
2
  import type { OwnerString, RepoString } from "../../types";
4
3
  export declare class GitHubTagManager {
5
4
  private readonly client;
6
5
  private readonly isExplicitToken;
7
- static readonly BASE_VERSION = "1.0.0";
8
6
  constructor(client: Octokit, isExplicitToken: boolean);
9
7
  private checkToken;
10
8
  /**
@@ -19,10 +17,12 @@ export declare class GitHubTagManager {
19
17
  * @note You **must** pass in a GitHub token because the regular Github bot token
20
18
  * cannot trigger actions (due to fear of recursion). You must either provide a GitHub App token or
21
19
  * a GitHub PAT.
20
+ *
21
+ * @note you should use `VersioningClient` to generate `nextTag`
22
22
  */
23
- createTag({ repositoryOverride, releaseType, onPreTagCreate, }: {
23
+ createTag({ nextTag, repositoryOverride, onPreTagCreate, }: {
24
+ nextTag: string;
24
25
  repositoryOverride?: [OwnerString, RepoString];
25
- releaseType?: semver.ReleaseType;
26
26
  onPreTagCreate?: (tag: string) => Promise<void>;
27
27
  }): Promise<void>;
28
28
  private parseRepository;
@@ -4,7 +4,6 @@ import semver from "semver";
4
4
  export class GitHubTagManager {
5
5
  client;
6
6
  isExplicitToken;
7
- static BASE_VERSION = "1.0.0";
8
7
  constructor(client, isExplicitToken) {
9
8
  this.client = client;
10
9
  this.isExplicitToken = isExplicitToken;
@@ -37,19 +36,12 @@ export class GitHubTagManager {
37
36
  * @note You **must** pass in a GitHub token because the regular Github bot token
38
37
  * cannot trigger actions (due to fear of recursion). You must either provide a GitHub App token or
39
38
  * a GitHub PAT.
39
+ *
40
+ * @note you should use `VersioningClient` to generate `nextTag`
40
41
  */
41
- async createTag({ repositoryOverride, releaseType, onPreTagCreate, }) {
42
+ async createTag({ nextTag, repositoryOverride, onPreTagCreate, }) {
42
43
  this.checkToken();
43
44
  const [owner, repo] = this.parseRepository(repositoryOverride);
44
- const lastTag = await this.getLatestTag({
45
- repositoryOverride: [owner, repo],
46
- });
47
- const nextTag = lastTag ?
48
- semver.inc(lastTag, releaseType ?? "patch")
49
- : GitHubTagManager.BASE_VERSION;
50
- if (!nextTag) {
51
- throw new Error("Could not increment version");
52
- }
53
45
  const { data: repository } = await this.client.rest.repos.get({
54
46
  owner,
55
47
  repo,
@@ -1,6 +1,7 @@
1
1
  import { EnvClient, EnvClientStrategy } from "../../env";
2
2
  import { GitHubClient } from "../../gh";
3
3
  import { Utils } from "../../utils";
4
+ import { VersioningClient, VersionUpdatingStrategy } from "../../versioning";
4
5
  async function main() {
5
6
  const envClient = EnvClient.create(EnvClientStrategy.GIT_CRYPT);
6
7
  const { githubAppAppId, githubAppInstallationId, githubAppPrivateKeyB64 } = parseCiEnv(await envClient.readFromEnv(".env.ci"));
@@ -9,7 +10,10 @@ async function main() {
9
10
  installationId: githubAppInstallationId,
10
11
  privateKey: await Utils.decodeBase64EncodedString(githubAppPrivateKeyB64),
11
12
  });
13
+ const versioningClient = new VersioningClient(ghClient, VersionUpdatingStrategy.JSTS);
14
+ const rootPkgJson = await Bun.file("./package.json").json();
12
15
  await ghClient.createTag({
16
+ nextTag: await versioningClient.next(rootPkgJson.version),
13
17
  onPreTagCreate: async (tag) => {
14
18
  const file = Bun.file("./package.json");
15
19
  const pkg = await file.json();
@@ -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,10 +26,9 @@ 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
- const lastTag = (await ghClient.getLatestTag()) ?? GitHubClient.BASE_VERSION;
32
- const betaVersion = `${lastTag}-beta.${shortSha}`;
31
+ const betaVersion = await versioningClient.nextBeta(shortSha);
33
32
  if (!Utils.SemVer.validate(betaVersion)) {
34
33
  throw new Error(`Generated invalid beta version: ${betaVersion}`);
35
34
  }
@@ -1,7 +1,34 @@
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>;
26
+ /**
27
+ * generate next beta version tag using a `sha`.
28
+ *
29
+ * simply finds latest version from github and generates `{version}-beta.{sha}` to it.
30
+ *
31
+ * for example, `1.3.2-beta.58cf28bd`
32
+ */
33
+ nextBeta(sha: string, ...opts: Parameters<GitHubClient["getLatestTag"]>): Promise<string>;
7
34
  }
@@ -1,20 +1,85 @@
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
+ }
70
+ /**
71
+ * generate next beta version tag using a `sha`.
72
+ *
73
+ * simply finds latest version from github and generates `{version}-beta.{sha}` to it.
74
+ *
75
+ * for example, `1.3.2-beta.58cf28bd`
76
+ */
77
+ async nextBeta(sha, ...opts) {
78
+ const latestTag = await this.githubClient.getLatestTag(...opts);
79
+ if (!latestTag) {
80
+ throw new Error("You must upload a tag atleast once before generating a beta tag.");
81
+ }
82
+ const latest = this.parseOrThrow("latest tag from github", latestTag);
83
+ return `${latest.toString()}-beta.${sha}`;
84
+ }
20
85
  }
@@ -1,11 +1,38 @@
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>;
24
+ /**
25
+ * generate next beta version tag.
26
+ *
27
+ * simply finds latest version from github and generates `{version}-beta.{sha}` to it.
28
+ *
29
+ * @note you may pass in the first 8 characters of `sha` if you choose.
30
+ *
31
+ * for example, `1.3.2-beta.58cf28bd`
32
+ */
33
+ nextBeta(sha: string): Promise<string>;
9
34
  }
10
- export interface IJavaMavenVersioningClient extends IVersioningClient {
35
+ export interface IJavascriptPackageJsonVersionUpdatingClient extends IVersionUpdatingClient {
36
+ }
37
+ export interface IJavaMavenVersionUpdatingClient extends IVersionUpdatingClient {
11
38
  }
@@ -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.58",
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
- }