Skip to content

Commit 7f06dc6

Browse files
committed
add sonarcloud action
1 parent fb93b1f commit 7f06dc6

3 files changed

Lines changed: 143 additions & 1 deletion

File tree

.github/workflows/sonarcloud.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: SonarCloud Analysis
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+
sonarcloud:
16+
name: SonarCloud
17+
runs-on: macos-latest # Using macOS runner for Android emulator
18+
19+
steps:
20+
- name: Harden Runner
21+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
22+
with:
23+
egress-policy: audit
24+
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
28+
29+
- name: Set up JDK 17
30+
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
31+
with:
32+
java-version: "17"
33+
distribution: "temurin"
34+
cache: gradle
35+
36+
- name: Setup Android SDK
37+
uses: android-actions/setup-android@93d4c24be58948622721d1eb2a1eee1ca3c2c16c # v3.2.0
38+
39+
- name: AVD cache
40+
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
41+
id: avd-cache
42+
with:
43+
path: |
44+
~/.android/avd/*
45+
~/.android/adb*
46+
key: avd-${{ runner.os }}
47+
48+
- name: Create AVD and generate snapshot for caching
49+
if: steps.avd-cache.outputs.cache-hit != 'true'
50+
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2.30.1
51+
with:
52+
api-level: 33
53+
target: google_apis
54+
arch: x86_64
55+
profile: pixel_6
56+
force-avd-creation: false
57+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
58+
disable-animations: false
59+
script: echo "Generated AVD snapshot."
60+
61+
- name: Run Instrumented Tests
62+
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2.30.1
63+
with:
64+
api-level: 33
65+
target: google_apis
66+
arch: x86_64
67+
profile: pixel_6
68+
script: |
69+
./gradlew jacocoAndroidTestReport
70+
71+
- name: SonarCloud Scan
72+
uses: SonarSource/sonarcloud-github-action@master
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
76+
with:
77+
args: >
78+
-Dsonar.organization=formbricks
79+
-Dsonar.projectKey=formbricks_android
80+
-Dsonar.java.binaries=android/build/tmp/kotlin-classes/debug
81+
-Dsonar.sources=android/src/main/java
82+
-Dsonar.tests=android/src/androidTest/java
83+
-Dsonar.coverage.jacoco.xmlReportPaths=android/build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies {
1717
}
1818
```
1919

20-
Enable DataBinding in your apps module build.gradle.kts:
20+
Enable DataBinding in your app's module build.gradle.kts:
2121

2222
```kotlin
2323
android {
@@ -63,6 +63,42 @@ Formbricks.logout()
6363

6464
We welcome issues and pull requests on our GitHub repository.
6565

66+
## Testing and Code Coverage
67+
68+
### Running Tests
69+
70+
To run the instrumented tests, make sure you have an Android emulator running or a physical device connected, then execute:
71+
72+
```bash
73+
./gradlew connectedDebugAndroidTest
74+
```
75+
76+
### Generating Coverage Reports
77+
78+
The SDK uses JaCoCo for code coverage reporting. To generate a coverage report for instrumented tests:
79+
80+
1. Make sure you have an Android emulator running or a physical device connected
81+
2. Run the provided script:
82+
```bash
83+
./generate-instrumented-coverage.sh
84+
```
85+
This will:
86+
- Run the instrumented tests
87+
- Generate a JaCoCo coverage report
88+
- Open the HTML report in your default browser
89+
90+
Alternatively, you can run the Gradle task directly:
91+
92+
```bash
93+
./gradlew jacocoAndroidTestReport
94+
```
95+
96+
The coverage report will be generated at:
97+
98+
```
99+
android/build/reports/jacoco/jacocoAndroidTestReport/html/index.html
100+
```
101+
66102
## License
67103

68104
This SDK is released under the MIT License.

sonar-project.properties

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sonar.projectKey=formbricks_android
2+
sonar.organization=formbricks
3+
4+
# Sources
5+
sonar.sources=android/src/main/java
6+
sonar.java.source=11
7+
8+
# Tests
9+
sonar.tests=android/src/androidTest/java
10+
sonar.junit.reportPaths=android/build/outputs/androidTest-results/connected
11+
12+
# Coverage
13+
sonar.coverage.jacoco.xmlReportPaths=android/build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml
14+
15+
# Encoding of the source code. Default is default system encoding
16+
sonar.sourceEncoding=UTF-8
17+
18+
# Exclusions
19+
sonar.exclusions=**/test/**/*,**/androidTest/**/*,**/*.js,**/*.json
20+
sonar.coverage.exclusions=**/test/**/*,**/androidTest/**/*,**/*.js,**/*.json
21+
22+
# Debug
23+
sonar.verbose=true

0 commit comments

Comments
 (0)