@tahminator/pipeline 1.0.18 → 1.0.20

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,5 +1,6 @@
1
1
  export * from "./gh";
2
2
  export * from "./docker";
3
3
  export * from "./npm";
4
+ export * from "./sonar";
4
5
  export * from "./types";
5
6
  export * from "./utils";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./gh";
2
2
  export * from "./docker";
3
3
  export * from "./npm";
4
+ export * from "./sonar";
4
5
  export * from "./types";
5
6
  export * from "./utils";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @beta WIP
3
+ */
4
+ export declare class SonarScannerClient {
5
+ private readonly opts;
6
+ private constructor();
7
+ runTests(): Promise<void>;
8
+ uploadTests(): Promise<void>;
9
+ }
@@ -0,0 +1,30 @@
1
+ import { $ } from "bun";
2
+ import { isCmdAvailable } from "../utils/cmd";
3
+ /**
4
+ * @beta WIP
5
+ */
6
+ export class SonarScannerClient {
7
+ opts;
8
+ constructor(opts) {
9
+ this.opts = opts;
10
+ }
11
+ async runTests() {
12
+ await this.opts.run.runTestsCmd;
13
+ }
14
+ async uploadTests() {
15
+ if (!(await isCmdAvailable("sonar"))) {
16
+ console.log("Sonar is missing, installing globally via NPM...");
17
+ await $ `npm i -g @sonar/scan`;
18
+ }
19
+ const { auth, scan } = this.opts;
20
+ const args = [
21
+ `-Dsonar.host.url=${scan.hostUrl ?? "https://sonarcloud.io"}`,
22
+ `-Dsonar.token=${auth.token}`,
23
+ `-Dsonar.projectKey=${scan.projectKey}`,
24
+ `-Dsonar.organization=${scan.organization}`,
25
+ `-Dsonar.sources=${scan.sourceCodeDir}`,
26
+ ...Object.entries(scan.additionalArgs ?? {}).map(([k, v]) => `-Dsonar.${k}=${v}`),
27
+ ];
28
+ await $ `sonar ${args}`;
29
+ }
30
+ }
@@ -0,0 +1 @@
1
+ export * from "./client";
@@ -0,0 +1 @@
1
+ export * from "./client";
@@ -0,0 +1 @@
1
+ export declare function isCmdAvailable(cmd: string): Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ import { $ } from "bun";
2
+ import { fromPromise } from "neverthrow";
3
+ const GENERIC_ERROR = 1;
4
+ const SUCCESS = 0;
5
+ export async function isCmdAvailable(cmd) {
6
+ return ((await fromPromise($ `which -v ${cmd}`.quiet(), (e) => e)
7
+ .map((s) => s.exitCode)
8
+ .unwrapOr(GENERIC_ERROR)) === SUCCESS);
9
+ }
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.18",
6
+ "version": "1.0.20",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -49,6 +49,7 @@
49
49
  "@octokit/rest": "^22.0.1",
50
50
  "@types/semver": "^7.7.1",
51
51
  "@types/yargs": "^17.0.35",
52
+ "neverthrow": "^8.2.0",
52
53
  "semver": "^7.7.4",
53
54
  "yaml": "^2.8.2",
54
55
  "yargs": "^18.0.0",