@tahminator/pipeline 1.0.22 → 1.0.24
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/gh/client.d.ts +27 -1
- package/dist/gh/client.js +41 -9
- package/dist/internal/create-tag/index.js +24 -6
- package/dist/utils/b64.d.ts +1 -0
- package/dist/utils/b64.js +3 -0
- package/dist/utils/client.d.ts +2 -0
- package/dist/utils/client.js +4 -0
- package/package.json +2 -1
package/dist/gh/client.d.ts
CHANGED
|
@@ -7,7 +7,33 @@ export declare class GitHubClient {
|
|
|
7
7
|
private readonly tagManager;
|
|
8
8
|
private readonly outputManager;
|
|
9
9
|
private readonly prManager;
|
|
10
|
-
constructor(
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
|
|
13
|
+
*/
|
|
14
|
+
static createWithGithubAppToken({ appId, privateKey, installationId, }: {
|
|
15
|
+
/**
|
|
16
|
+
* get it from https://github.com/settings/apps/<appName> -> `Client ID` or `App ID`
|
|
17
|
+
*/
|
|
18
|
+
appId: string;
|
|
19
|
+
privateKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* get it from github.com/settings/installations/<installationId>
|
|
22
|
+
*/
|
|
23
|
+
installationId: string;
|
|
24
|
+
}): Promise<GitHubClient>;
|
|
25
|
+
/**
|
|
26
|
+
* __It is highly recommended that you use `createWithGithubAppToken`, unless you need the "dumb"
|
|
27
|
+
* features of this client such as, for example, outputting data to `$GITHUB_ENV`__
|
|
28
|
+
*
|
|
29
|
+
* This is because the default CI token is not eligible for any automation whatsoever. That includes triggering
|
|
30
|
+
* CI based off pushes, merges, or anything else of the like.
|
|
31
|
+
*/
|
|
32
|
+
static createWithDefaultCiToken(): Promise<GitHubClient>;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated use `createWithGithubAppToken`
|
|
35
|
+
*/
|
|
36
|
+
static createWithPatCiToken(pat: string): Promise<GitHubClient>;
|
|
11
37
|
createTag(...args: Parameters<GitHubTagManager["createTag"]>): Promise<void>;
|
|
12
38
|
outputToGithubOutput(...args: Parameters<GitHubOutputManager["outputToGithubOutput"]>): Promise<void>;
|
|
13
39
|
updateK8sTagWithPR(...args: Parameters<GitHubPRManager["updateK8sTagWithPR"]>): Promise<void>;
|
package/dist/gh/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createAppAuth } from "@octokit/auth-app";
|
|
1
2
|
import { Octokit } from "@octokit/rest";
|
|
2
3
|
import { GitHubOutputManager } from "./output";
|
|
3
4
|
import { GitHubPRManager } from "./pr";
|
|
@@ -8,19 +9,50 @@ export class GitHubClient {
|
|
|
8
9
|
tagManager;
|
|
9
10
|
outputManager;
|
|
10
11
|
prManager;
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
if (!token) {
|
|
15
|
-
throw new Error("No GitHub token has been provided & GH_TOKEN cannot be found in environment");
|
|
16
|
-
}
|
|
17
|
-
this.client = new Octokit({
|
|
18
|
-
auth: token,
|
|
19
|
-
});
|
|
12
|
+
constructor(client, isExplicitToken) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
this.isExplicitToken = isExplicitToken;
|
|
20
15
|
this.tagManager = new GitHubTagManager(this.client, this.isExplicitToken);
|
|
21
16
|
this.outputManager = new GitHubOutputManager();
|
|
22
17
|
this.prManager = new GitHubPRManager(this.client);
|
|
23
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
|
|
21
|
+
*/
|
|
22
|
+
static async createWithGithubAppToken({ appId, privateKey, installationId, }) {
|
|
23
|
+
return new this(new Octokit({
|
|
24
|
+
authStrategy: createAppAuth,
|
|
25
|
+
auth: {
|
|
26
|
+
appId,
|
|
27
|
+
privateKey,
|
|
28
|
+
installationId,
|
|
29
|
+
},
|
|
30
|
+
}), true);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* __It is highly recommended that you use `createWithGithubAppToken`, unless you need the "dumb"
|
|
34
|
+
* features of this client such as, for example, outputting data to `$GITHUB_ENV`__
|
|
35
|
+
*
|
|
36
|
+
* This is because the default CI token is not eligible for any automation whatsoever. That includes triggering
|
|
37
|
+
* CI based off pushes, merges, or anything else of the like.
|
|
38
|
+
*/
|
|
39
|
+
static async createWithDefaultCiToken() {
|
|
40
|
+
const token = process.env.GH_TOKEN;
|
|
41
|
+
if (!token) {
|
|
42
|
+
throw new Error("GH_TOKEN cannot be found in environment");
|
|
43
|
+
}
|
|
44
|
+
return new this(new Octokit({
|
|
45
|
+
auth: token,
|
|
46
|
+
}), false);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated use `createWithGithubAppToken`
|
|
50
|
+
*/
|
|
51
|
+
static async createWithPatCiToken(pat) {
|
|
52
|
+
return new this(new Octokit({
|
|
53
|
+
auth: pat,
|
|
54
|
+
}), true);
|
|
55
|
+
}
|
|
24
56
|
createTag(...args) {
|
|
25
57
|
return this.tagManager.createTag(...args);
|
|
26
58
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { GitHubClient } from "../../gh";
|
|
2
2
|
import { Utils } from "../../utils";
|
|
3
3
|
async function main() {
|
|
4
|
-
const {
|
|
5
|
-
const ghClient =
|
|
4
|
+
const { githubAppAppId, githubAppInstallationId, githubAppPrivateKeyB64 } = parseCiEnv(await Utils.getEnvVariables(["ci"]));
|
|
5
|
+
const ghClient = await GitHubClient.createWithGithubAppToken({
|
|
6
|
+
appId: githubAppAppId,
|
|
7
|
+
installationId: githubAppInstallationId,
|
|
8
|
+
privateKey: await Utils.decodeBase64EncodedString(githubAppPrivateKeyB64),
|
|
9
|
+
});
|
|
6
10
|
await ghClient.createTag({
|
|
7
11
|
onPreTagCreate: async (tag) => {
|
|
8
12
|
const file = Bun.file("./package.json");
|
|
@@ -14,14 +18,28 @@ async function main() {
|
|
|
14
18
|
});
|
|
15
19
|
}
|
|
16
20
|
function parseCiEnv(ciEnv) {
|
|
17
|
-
const
|
|
18
|
-
const v = ciEnv["
|
|
21
|
+
const githubAppAppId = (() => {
|
|
22
|
+
const v = ciEnv["GITHUB_APP_APP_ID"];
|
|
23
|
+
if (!v) {
|
|
24
|
+
throw new Error("Missing GITHUB_APP_APP_ID from .env.ci");
|
|
25
|
+
}
|
|
26
|
+
return v;
|
|
27
|
+
})();
|
|
28
|
+
const githubAppInstallationId = (() => {
|
|
29
|
+
const v = ciEnv["GITHUB_APP_INSTALLATION_ID"];
|
|
30
|
+
if (!v) {
|
|
31
|
+
throw new Error("Missing GITHUB_APP_INSTALLATION_ID from .env.ci");
|
|
32
|
+
}
|
|
33
|
+
return v;
|
|
34
|
+
})();
|
|
35
|
+
const githubAppPrivateKeyB64 = (() => {
|
|
36
|
+
const v = ciEnv["GITHUB_APP_PRIVATE_KEY_B64"];
|
|
19
37
|
if (!v) {
|
|
20
|
-
throw new Error("Missing
|
|
38
|
+
throw new Error("Missing GITHUB_APP_PRIVATE_KEY_B64 from .env.ci");
|
|
21
39
|
}
|
|
22
40
|
return v;
|
|
23
41
|
})();
|
|
24
|
-
return {
|
|
42
|
+
return { githubAppAppId, githubAppInstallationId, githubAppPrivateKeyB64 };
|
|
25
43
|
}
|
|
26
44
|
main()
|
|
27
45
|
.then(() => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function decodeBase64EncodedString(s: string): string;
|
package/dist/utils/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeBase64EncodedString } from "./b64";
|
|
1
2
|
import { isCmdAvailable } from "./cmd";
|
|
2
3
|
import { Colors } from "./colors";
|
|
3
4
|
import { getEnvVariables } from "./env";
|
|
@@ -10,4 +11,5 @@ export declare class Utils {
|
|
|
10
11
|
static generateShortId(...args: Parameters<typeof generateShortId>): string;
|
|
11
12
|
static updateAllPackageJsonsWithVersion(version: string): Promise<void>;
|
|
12
13
|
static isCmdAvailable(...args: Parameters<typeof isCmdAvailable>): Promise<boolean>;
|
|
14
|
+
static decodeBase64EncodedString(...args: Parameters<typeof decodeBase64EncodedString>): Promise<string>;
|
|
13
15
|
}
|
package/dist/utils/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { $ } from "bun";
|
|
2
|
+
import { decodeBase64EncodedString } from "./b64";
|
|
2
3
|
import { isCmdAvailable } from "./cmd";
|
|
3
4
|
import { Colors } from "./colors";
|
|
4
5
|
import { getEnvVariables } from "./env";
|
|
@@ -29,4 +30,7 @@ export class Utils {
|
|
|
29
30
|
static async isCmdAvailable(...args) {
|
|
30
31
|
return isCmdAvailable(...args);
|
|
31
32
|
}
|
|
33
|
+
static async decodeBase64EncodedString(...args) {
|
|
34
|
+
return decodeBase64EncodedString(...args);
|
|
35
|
+
}
|
|
32
36
|
}
|
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.24",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "git+https://github.com/tahminator/pipeline.git"
|
|
9
9
|
},
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"typescript": "^5"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@octokit/auth-app": "^8.2.0",
|
|
49
50
|
"@octokit/rest": "^22.0.1",
|
|
50
51
|
"@types/semver": "^7.7.1",
|
|
51
52
|
"@types/yargs": "^17.0.35",
|