@tahminator/pipeline 1.0.55 → 1.0.56-beta.f14b8709
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/upload-npm/beta/index.js +4 -1
- package/dist/utils/client.d.ts +0 -1
- package/dist/utils/client.js +0 -13
- package/dist/versioning/client.d.ts +26 -0
- package/dist/versioning/client.js +70 -0
- package/dist/versioning/index.d.ts +2 -0
- package/dist/versioning/index.js +2 -0
- package/dist/versioning/types.d.ts +28 -0
- package/dist/versioning/types.js +5 -0
- package/dist/versioning/updating/base.d.ts +6 -0
- package/dist/versioning/updating/base.js +16 -0
- package/dist/versioning/updating/java/maven/index.d.ts +6 -0
- package/dist/versioning/updating/java/maven/index.js +28 -0
- package/dist/versioning/updating/jsts/index.d.ts +5 -0
- package/dist/versioning/updating/jsts/index.js +13 -0
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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 { VersionUpdatingStrategy } 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(ghClient, VersionUpdatingStrategy.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
|
|
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({
|
package/dist/utils/client.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/utils/client.js
CHANGED
|
@@ -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,26 @@
|
|
|
1
|
+
import type { GitHubClient } from "../gh";
|
|
2
|
+
import { VersionUpdatingStrategy, type IVersioningClient } from "./types";
|
|
3
|
+
export declare class VersioningClient implements IVersioningClient {
|
|
4
|
+
private readonly githubClient;
|
|
5
|
+
private static readonly INITIAL_VERSION;
|
|
6
|
+
private readonly delegate;
|
|
7
|
+
constructor(githubClient: GitHubClient, strategy: VersionUpdatingStrategy);
|
|
8
|
+
private getDelegate;
|
|
9
|
+
private parseOrThrow;
|
|
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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
import { VersionUpdatingStrategy, } from "./types";
|
|
3
|
+
import { JavaMavenVersioningClient } from "./updating/java/maven";
|
|
4
|
+
import { JavascriptPackageJsonVersioningClient } from "./updating/jsts";
|
|
5
|
+
export class VersioningClient {
|
|
6
|
+
githubClient;
|
|
7
|
+
static INITIAL_VERSION = "1.0.0";
|
|
8
|
+
delegate;
|
|
9
|
+
constructor(githubClient, strategy) {
|
|
10
|
+
this.githubClient = githubClient;
|
|
11
|
+
this.delegate = this.getDelegate(strategy);
|
|
12
|
+
}
|
|
13
|
+
getDelegate(strategy) {
|
|
14
|
+
switch (strategy) {
|
|
15
|
+
case VersionUpdatingStrategy.JSTS:
|
|
16
|
+
return new JavascriptPackageJsonVersioningClient();
|
|
17
|
+
case VersionUpdatingStrategy.JAVA_MAVEN:
|
|
18
|
+
return new JavaMavenVersioningClient();
|
|
19
|
+
}
|
|
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
|
+
}
|
|
28
|
+
async update(version) {
|
|
29
|
+
await this.delegate.update(version);
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare enum VersionUpdatingStrategy {
|
|
2
|
+
JSTS = 0,
|
|
3
|
+
JAVA_MAVEN = 1
|
|
4
|
+
}
|
|
5
|
+
export interface IVersionUpdatingClient {
|
|
6
|
+
update(version: string): Promise<void>;
|
|
7
|
+
}
|
|
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
|
+
export interface IJavascriptPackageJsonVersionUpdatingClient extends IVersionUpdatingClient {
|
|
26
|
+
}
|
|
27
|
+
export interface IJavaMavenVersionUpdatingClient extends IVersionUpdatingClient {
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export var VersionUpdatingStrategy;
|
|
2
|
+
(function (VersionUpdatingStrategy) {
|
|
3
|
+
VersionUpdatingStrategy[VersionUpdatingStrategy["JSTS"] = 0] = "JSTS";
|
|
4
|
+
VersionUpdatingStrategy[VersionUpdatingStrategy["JAVA_MAVEN"] = 1] = "JAVA_MAVEN";
|
|
5
|
+
})(VersionUpdatingStrategy || (VersionUpdatingStrategy = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IVersionUpdatingClient } from "../types";
|
|
2
|
+
export declare abstract class BaseVersionUpdatingClient implements IVersionUpdatingClient {
|
|
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 BaseVersionUpdatingClient {
|
|
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,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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { XmlElement, XmlParser, XmlText } from "xml-trueformat";
|
|
2
|
+
import { BaseVersionUpdatingClient } from "../../base";
|
|
3
|
+
export class JavaMavenVersioningClient extends BaseVersionUpdatingClient {
|
|
4
|
+
getVersionNode(projectNode) {
|
|
5
|
+
const versionNode = projectNode.children.find((child) => child instanceof XmlElement && child.tagName === "version");
|
|
6
|
+
if (!versionNode) {
|
|
7
|
+
throw new Error("Can't find version tag inside of project tag in pom.xml");
|
|
8
|
+
}
|
|
9
|
+
return versionNode;
|
|
10
|
+
}
|
|
11
|
+
async update(version) {
|
|
12
|
+
const files = await this.findFiles("pom.xml");
|
|
13
|
+
for (const fileLocation of files) {
|
|
14
|
+
const file = Bun.file(fileLocation);
|
|
15
|
+
const oldPomStr = await file.text();
|
|
16
|
+
const pom = XmlParser.parse(oldPomStr);
|
|
17
|
+
const projectNode = pom.getRootElement();
|
|
18
|
+
if (projectNode.tagName !== "project") {
|
|
19
|
+
throw new Error("Can't find project tag inside of pom.xml");
|
|
20
|
+
}
|
|
21
|
+
const versionNode = this.getVersionNode(projectNode);
|
|
22
|
+
versionNode.children = [new XmlText(version)];
|
|
23
|
+
const newPomStr = pom.toString();
|
|
24
|
+
await Bun.write(fileLocation, newPomStr);
|
|
25
|
+
this.logFileLocationUpdated(fileLocation, version);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseVersionUpdatingClient } from "../base";
|
|
2
|
+
export class JavascriptPackageJsonVersioningClient extends BaseVersionUpdatingClient {
|
|
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
|
+
}
|
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.
|
|
6
|
+
"version": "1.0.56-beta.f14b8709",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "git+https://github.com/tahminator/pipeline.git"
|
|
9
9
|
},
|
|
@@ -52,8 +52,11 @@
|
|
|
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",
|
|
59
|
+
"xml-trueformat": "^0.9.5",
|
|
57
60
|
"yaml": "^2.8.2",
|
|
58
61
|
"yargs": "^18.0.0",
|
|
59
62
|
"zod": "^4.3.6"
|