Skip to content

Commit 0288b21

Browse files
feat: adds tests, sonar config and workflows (#6)
* adds tests, sonar config and workflows * pins setup action to a SHA * sonar issues * it -> test * feedback * feedback * harden the actions --------- Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
1 parent 544aa92 commit 0288b21

13 files changed

Lines changed: 1727 additions & 140 deletions

File tree

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build JS Package
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
merge_group:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
name: "Build and Test Package"
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
20+
steps:
21+
- name: Harden the runner
22+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
23+
with:
24+
egress-policy: audit
25+
26+
- name: Checkout code
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
29+
- name: Setup Node.js 22.x
30+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
31+
with:
32+
node-version: 22.x
33+
34+
- name: Install pnpm
35+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
36+
37+
- name: Install dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Build
41+
run: pnpm build

.github/workflows/release.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Release JS SDK
2+
3+
permissions:
4+
id-token: write # Required for npm provenance
5+
contents: read
6+
7+
on:
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
release:
13+
name: "Publish Package to npm"
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
17+
steps:
18+
- name: Harden the runner
19+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
20+
with:
21+
egress-policy: audit
22+
23+
- name: Checkout code
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
26+
- name: Setup Node.js 22.x
27+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
28+
with:
29+
node-version: 22.x
30+
registry-url: "https://registry.npmjs.org"
31+
cache: "pnpm"
32+
always-auth: true
33+
34+
- name: Install pnpm
35+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
36+
37+
- name: Install dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Build package
41+
run: |
42+
cd packages/js
43+
pnpm build
44+
45+
- name: Run tests
46+
run: pnpm test:coverage
47+
48+
- name: Publish to npm
49+
run: |
50+
cd packages/js
51+
npm publish --access public --provenance
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/sonarqube.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: SonarQube
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
merge_group:
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
sonarqube:
15+
name: SonarQube
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Harden the runner
20+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: Checkout code
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
27+
- name: Setup Node.js 22.x
28+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
with:
30+
node-version: 22.x
31+
32+
- name: Install pnpm
33+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
34+
35+
- name: Install dependencies
36+
run: pnpm install --frozen-lockfile
37+
38+
- name: Run tests with coverage
39+
run: |
40+
pnpm test:coverage
41+
42+
- name: SonarQube Scan
43+
uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
46+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Run unit tests for js package
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
merge_group:
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
test:
15+
name: "Test Package"
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Harden the runner
20+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: Checkout code
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
27+
- name: Setup Node.js 22.x
28+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
with:
30+
node-version: 22.x
31+
32+
- name: Install pnpm
33+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
34+
35+
- name: Install dependencies
36+
run: pnpm install --frozen-lockfile
37+
38+
- name: Test
39+
run: pnpm test

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
{
44
"mode": "auto"
55
}
6-
]
6+
],
7+
"sonarlint.connectedMode.project": {
8+
"connectionId": "formbricks",
9+
"projectKey": "formbricks_js"
10+
}
711
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"dev": "turbo run dev",
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
9-
"check-types": "turbo run check-types"
9+
"check-types": "turbo run check-types",
10+
"test": "turbo run test --no-cache",
11+
"test:coverage": "turbo run test:coverage --no-cache"
1012
},
1113
"devDependencies": {
1214
"prettier": "^3.5.3",

packages/js/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@
3636
"build:dev": "tsc && vite build --mode dev",
3737
"go": "vite build --watch --mode dev",
3838
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",
39-
"clean": "rimraf .turbo node_modules dist coverage"
39+
"clean": "rimraf .turbo node_modules dist coverage",
40+
"test": "vitest run",
41+
"test:coverage": "vitest run --coverage"
4042
},
4143
"author": "Formbricks <hola@formbricks.com>",
4244
"devDependencies": {
4345
"@vercel/style-guide": "6.0.0",
46+
"@vitest/coverage-v8": "3.2.4",
4447
"terser": "5.39.0",
45-
"vite": "6.2.5",
46-
"vite-plugin-dts": "4.5.3"
48+
"vite": "7.1.7",
49+
"vite-plugin-dts": "4.5.3",
50+
"vitest": "3.2.4"
4751
}
4852
}

0 commit comments

Comments
 (0)