@tahminator/pipeline 1.0.8 → 1.0.10

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
@@ -1,4 +1,5 @@
1
1
  export * from "./gh";
2
2
  export * from "./docker";
3
+ export * from "./npm";
3
4
  export * from "./types";
4
5
  export * from "./utils";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./gh";
2
2
  export * from "./docker";
3
+ export * from "./npm";
3
4
  export * from "./types";
4
5
  export * from "./utils";
@@ -1,7 +1,7 @@
1
1
  import { GitHubClient } from "../../gh";
2
- import { getEnvVariables } from "../../utils/env";
2
+ import { Utils } from "../../utils";
3
3
  async function main() {
4
- const { githubPat } = parseCiEnv(await getEnvVariables(["ci"]));
4
+ const { githubPat } = parseCiEnv(await Utils.getEnvVariables(["ci"]));
5
5
  const ghClient = new GitHubClient(githubPat);
6
6
  await ghClient.createTag({
7
7
  onPreTagCreate: async (tag) => {
@@ -1,20 +1,16 @@
1
- import { $ } from "bun";
2
- import { getEnvVariables } from "../../utils/env";
1
+ import yargs from "yargs";
2
+ import { hideBin } from "yargs/helpers";
3
+ import { NPMClient } from "../../npm";
4
+ const { dryRun } = await yargs(hideBin(process.argv))
5
+ .option("dryRun", {
6
+ type: "boolean",
7
+ default: false,
8
+ })
9
+ .strict()
10
+ .parse();
3
11
  async function main() {
4
- const { npmToken } = parseCiEnv(await getEnvVariables(["ci"]));
5
- await $ `npm config set //registry.npmjs.org/:_authToken=${npmToken}`;
6
- await $ `npm publish --access public`;
7
- console.log("Package has been successfully published");
8
- }
9
- function parseCiEnv(ciEnv) {
10
- const npmToken = (() => {
11
- const v = ciEnv["NPM_TOKEN"];
12
- if (!v) {
13
- throw new Error("Missing NPM_TOKEN from .env.ci");
14
- }
15
- return v;
16
- })();
17
- return { npmToken };
12
+ await using npmClient = await NPMClient.create();
13
+ await npmClient.publish(dryRun);
18
14
  }
19
15
  main()
20
16
  .then(() => {
@@ -0,0 +1,24 @@
1
+ export declare class NPMClient {
2
+ private constructor();
3
+ /**
4
+ * __You must use [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) now.__ Using tokens
5
+ * now are extremely flaky and should be avoided.
6
+ *
7
+ * __NOTE: Base yaml must have this property__
8
+ *
9
+ * @example
10
+ * ```yaml
11
+ * permissions:
12
+ * id-token: write # Required for OIDC
13
+ * ```
14
+ */
15
+ static create(): Promise<NPMClient>;
16
+ /**
17
+ * @note You must ensure that the current root directory `package.json`
18
+ * is filled out with the name of the package and the version you would like to
19
+ * deploy.
20
+ */
21
+ publish(dryRun?: boolean): Promise<void>;
22
+ [Symbol.asyncDispose](): Promise<void>;
23
+ cleanup(): Promise<void>;
24
+ }
@@ -0,0 +1,43 @@
1
+ import { $ } from "bun";
2
+ import { Utils } from "../utils";
3
+ export class NPMClient {
4
+ constructor() { }
5
+ /**
6
+ * __You must use [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) now.__ Using tokens
7
+ * now are extremely flaky and should be avoided.
8
+ *
9
+ * __NOTE: Base yaml must have this property__
10
+ *
11
+ * @example
12
+ * ```yaml
13
+ * permissions:
14
+ * id-token: write # Required for OIDC
15
+ * ```
16
+ */
17
+ static async create() {
18
+ // await $`npm config set //registry.npmjs.org/:_authToken=${npmToken}`;
19
+ return new this();
20
+ }
21
+ /**
22
+ * @note You must ensure that the current root directory `package.json`
23
+ * is filled out with the name of the package and the version you would like to
24
+ * deploy.
25
+ */
26
+ async publish(dryRun) {
27
+ const dryRunFlag = dryRun ? ["--dry-run"] : [];
28
+ if (Utils.Log.isDebug) {
29
+ console.log(await $ `ls .`.text());
30
+ console.log(await $ `ls ./dist/`.text());
31
+ console.log(await $ `pwd`.text());
32
+ console.log(await $ `cat ./package.json`.text());
33
+ }
34
+ await $ `npm publish --access public --provenance ${dryRunFlag} ./`;
35
+ console.log("Package has been successfully published");
36
+ }
37
+ async [Symbol.asyncDispose]() {
38
+ await this.cleanup();
39
+ }
40
+ async cleanup() {
41
+ await $ `npm logout`;
42
+ }
43
+ }
@@ -0,0 +1 @@
1
+ export * from "./client";
@@ -0,0 +1 @@
1
+ export * from "./client";
@@ -1,8 +1,10 @@
1
1
  import { Colors } from "./colors";
2
2
  import { getEnvVariables } from "./env";
3
+ import { Log } from "./log";
3
4
  import { generateShortId } from "./short";
4
5
  export declare class Utils {
5
6
  static Colors: typeof Colors;
7
+ static Log: typeof Log;
6
8
  static getEnvVariables(...args: Parameters<typeof getEnvVariables>): Promise<Record<string, string>>;
7
9
  static generateShortId(...args: Parameters<typeof generateShortId>): string;
8
10
  static updateAllPackageJsonsWithVersion(version: string): Promise<void>;
@@ -1,10 +1,12 @@
1
1
  import { $ } from "bun";
2
2
  import { Colors } from "./colors";
3
3
  import { getEnvVariables } from "./env";
4
+ import { Log } from "./log";
4
5
  import { generateShortId } from "./short";
5
6
  export class Utils {
6
7
  // hoist
7
8
  static Colors = Colors;
9
+ static Log = Log;
8
10
  static getEnvVariables(...args) {
9
11
  return getEnvVariables(...args);
10
12
  }
@@ -0,0 +1,3 @@
1
+ export declare class Log {
2
+ static get isDebug(): boolean;
3
+ }
@@ -0,0 +1,6 @@
1
+ export class Log {
2
+ // automatically injected from setup action in CI
3
+ static get isDebug() {
4
+ return process.env.DEBUG === "true";
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@tahminator/pipeline",
3
3
  "type": "module",
4
- "version": "1.0.8",
4
+ "author": "Tahmid Ahmed",
5
+ "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
6
+ "version": "1.0.10",
7
+ "repository": {
8
+ "url": "https://github.com/tahminator/pipeline"
9
+ },
5
10
  "main": "./dist/index.js",
6
11
  "module": "./dist/index.js",
7
12
  "types": "./dist/index.d.ts",
@@ -24,8 +29,7 @@
24
29
  "prettier": "prettier --check .",
25
30
  "prettier:fix": "prettier --write .",
26
31
  "vt": "vitest run",
27
- "build": "tsc -p tsconfig.build.json",
28
- "prepublishOnly": "bun run build"
32
+ "build": "tsc -p tsconfig.build.json"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@eslint/js": "^10.0.1",
@@ -44,8 +48,10 @@
44
48
  "dependencies": {
45
49
  "@octokit/rest": "^22.0.1",
46
50
  "@types/semver": "^7.7.1",
51
+ "@types/yargs": "^17.0.35",
47
52
  "semver": "^7.7.4",
48
53
  "yaml": "^2.8.2",
54
+ "yargs": "^18.0.0",
49
55
  "zod": "^4.3.6"
50
56
  }
51
57
  }