diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bd18e60 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +name: Build React Native Package and Playground +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + merge_group: +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build + run: pnpm build diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 0000000..0b28d17 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,40 @@ +name: SonarQube +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + merge_group: +permissions: + contents: read + +jobs: + sonarqube: + name: SonarQube + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests with coverage + run: | + pnpm test:coverage + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..96b9606 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Run unit tests for react-native package +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + merge_group: +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/apps/playground/package.json b/apps/playground/package.json index d8ff156..05939e3 100644 --- a/apps/playground/package.json +++ b/apps/playground/package.json @@ -6,7 +6,8 @@ "dev": "expo start --reset-cache", "android": "expo start --android", "ios": "expo start --ios", - "clean": "rimraf .turbo node_modules .expo" + "clean": "rimraf .turbo node_modules .expo", + "build": "expo export" }, "dependencies": { "@formbricks/react-native": "workspace:*", diff --git a/package.json b/package.json index 970b2a8..cd6aafd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "dev": "turbo run dev", "lint": "turbo run lint", "format": "prettier --write \"**/*.{ts,tsx,md}\"", - "check-types": "turbo run check-types" + "check-types": "turbo run check-types", + "test": "turbo run test --no-cache", + "test:coverage": "turbo run test:coverage --no-cache" }, "devDependencies": { "prettier": "^3.5.3", diff --git a/packages/react-native/package.json b/packages/react-native/package.json index bb29e77..ed827f2 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -38,7 +38,7 @@ "dev": "vite build --watch --mode dev", "clean": "rimraf .turbo node_modules dist .turbo", "test": "vitest", - "coverage": "vitest run --coverage" + "test:coverage": "vitest run --coverage" }, "dependencies": { "@react-native-community/netinfo": "11.4.1", diff --git a/packages/react-native/vite.config.ts b/packages/react-native/vite.config.ts index 2087bfa..ebca087 100644 --- a/packages/react-native/vite.config.ts +++ b/packages/react-native/vite.config.ts @@ -31,13 +31,16 @@ const config = (): UserConfig => { fileName: "index", }, }, - plugins: [dts({ rollupTypes: true, bundledPackages: ["@formbricks/types"] })], + plugins: [ + dts({ rollupTypes: true, bundledPackages: ["@formbricks/types"] }), + ], test: { setupFiles: ["./vitest.setup.ts"], coverage: { provider: "v8", - reporter: ["text", "json", "html"], - include: ["src/lib/**/*.ts"], + reporter: ["text", "json", "html", "lcov"], + include: ["src/**/*.ts"], + exclude: ["src/types/**/*.ts"], }, }, }); diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..8858a8d --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,21 @@ +# SonarQube Configuration for Formbricks React Native +sonar.projectKey=formbricks_react-native +sonar.organization=formbricks + +# Source code paths +sonar.sources=packages/react-native/src,apps/playground/src +sonar.tests=packages/react-native/src + +# Test inclusions and exclusions +sonar.test.inclusions=**/*.test.*,**/*.spec.* +sonar.test.exclusions=**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,**/.turbo/** + +# General exclusions +sonar.exclusions=**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,**/.turbo/**,**/apps/playground/**,**/*.config.js,**/*.config.ts,**/vite.config.ts,**/vitest.setup.ts,**/tsconfig.json,**/package.json,**/pnpm-lock.yaml,**/turbo.json,**/pnpm-workspace.yaml,**/assets/**,**/android/**,**/ios/**,**/android/**/*,**/ios/**/*,**/*.gradle,**/*.plist,**/*.pbxproj,**/*.xcworkspace,**/*.xcodeproj + +# Language specific settings +sonar.javascript.lcov.reportPaths=packages/react-native/coverage/lcov.info +sonar.typescript.tsconfigPath=packages/react-native/tsconfig.json,apps/playground/tsconfig.json + +# Coverage settings +sonar.coverage.exclusions=**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,**/.turbo/**,**/apps/playground/**,**/*.config.js,**/*.config.ts,**/vite.config.ts,**/vitest.setup.ts,**/tsconfig.json,**/package.json,**/pnpm-lock.yaml,**/turbo.json,**/pnpm-workspace.yaml diff --git a/turbo.json b/turbo.json index d508947..b039cea 100644 --- a/turbo.json +++ b/turbo.json @@ -16,6 +16,21 @@ "dev": { "cache": false, "persistent": true + }, + "@formbricks/react-native:build": { + "dependsOn": ["^build"], + "cache": false + }, + "playground:build": { + "dependsOn": ["@formbricks/react-native:build"], + "outputs": ["apps/playground/out/**"], + "cache": false + }, + "test": { + "outputs": [] + }, + "test:coverage": { + "outputs": [] } } }