|
| 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 |
0 commit comments