Update development branch (#862) #255
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: SonarCloud Analysis | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - development | ||
| - '*_baseline' | ||
| pull_request: | ||
| branches: | ||
| - '*' | ||
| push: | ||
| branches: | ||
| - master | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| sonarcloud: | ||
| name: SonarCloud Scan | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Shallow clones should be disabled for better relevancy of analysis | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: 17 | ||
| - name: Gradle cache | ||
| uses: gradle/actions/setup-gradle@v3 | ||
| - name: Configure Gradle memory settings | ||
| run: | | ||
| echo "org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError" >> gradle.properties | ||
| echo "android.enableJetifier=false" >> gradle.properties | ||
| echo "android.enableR8.fullMode=false" >> gradle.properties | ||
| cat gradle.properties | ||
| - name: Build project and run tests with coverage | ||
| run: | | ||
| # Build the project | ||
| ./gradlew assembleDebug | ||
| # Run tests - continue even if some tests fail | ||
| ./gradlew testDebugUnitTest || echo "Some tests failed, but continuing to generate coverage report..." | ||
| # Generate JaCoCo aggregate report separately (ensures it runs even if tests failed) | ||
| ./gradlew jacocoRootReport | ||
| # Log report location for debugging | ||
| REPORT_PATH="build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml" | ||
| if [ -f "$REPORT_PATH" ]; then | ||
| echo "✓ JaCoCo report generated at: $REPORT_PATH ($(wc -c < "$REPORT_PATH") bytes)" | ||
| else | ||
| echo "✗ JaCoCo report was NOT generated at: $REPORT_PATH" | ||
| fi | ||
| - name: Verify class files and coverage data for SonarQube analysis | ||
| run: | | ||
| echo "=== Verifying Build Artifacts for SonarQube ===" | ||
| echo "" | ||
| # Dynamically get modules from settings.gradle (extract module names from "include ':modulename'" lines) | ||
| MODULES=$(grep "^include" settings.gradle | cut -d"'" -f2 | cut -d":" -f2 | tr '\n' ' ') | ||
| echo "Detected modules: $MODULES" | ||
| echo "" | ||
| echo "Checking compiled class files for each module:" | ||
| for module in $MODULES; do | ||
| MODULE_CLASSES_DIR="${module}/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" | ||
| if [ -d "$MODULE_CLASSES_DIR" ]; then | ||
| CLASS_COUNT=$(find "$MODULE_CLASSES_DIR" -name "*.class" | wc -l) | ||
| echo " ✓ ${module}: Found $CLASS_COUNT class files in $MODULE_CLASSES_DIR" | ||
| else | ||
| echo " ✗ ${module}: Class directory not found: $MODULE_CLASSES_DIR" | ||
| fi | ||
| done | ||
| echo "" | ||
| echo "Checking JaCoCo coverage report:" | ||
| if [ -f build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml ]; then | ||
| REPORT_SIZE=$(wc -c < build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml) | ||
| PACKAGE_COUNT=$(grep -c "<package" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") | ||
| CLASS_COUNT=$(grep -c "<class" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") | ||
| LINE_COUNT=$(grep -c "<line" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") | ||
| COVERED_LINES=$(grep -c 'ci="1"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") | ||
| echo " ✓ JaCoCo report found: build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml" | ||
| echo " - Size: $REPORT_SIZE bytes" | ||
| echo " - Packages: $PACKAGE_COUNT" | ||
| echo " - Classes: $CLASS_COUNT" | ||
| echo " - Lines: $LINE_COUNT" | ||
| echo " - Covered lines: $COVERED_LINES" | ||
| # Check if events module coverage is present | ||
| if grep -q 'package name="io/harness/events"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml; then | ||
| echo " ✓ Events module (io/harness/events) coverage found in report" | ||
| else | ||
| echo " ✗ WARNING: Events module coverage NOT found in report" | ||
| fi | ||
| else | ||
| echo " ✗ JaCoCo report file not found" | ||
| fi | ||
| echo "" | ||
| echo "Checking JaCoCo execution data for each module:" | ||
| for module in $MODULES; do | ||
| EXEC_FILE="${module}/build/jacoco/testDebugUnitTest.exec" | ||
| if [ -f "$EXEC_FILE" ]; then | ||
| EXEC_SIZE=$(wc -c < "$EXEC_FILE") | ||
| echo " ✓ ${module}: Found execution data ($EXEC_SIZE bytes) in $EXEC_FILE" | ||
| else | ||
| echo " ✗ ${module}: Execution data not found: $EXEC_FILE" | ||
| fi | ||
| done | ||
| echo "" | ||
| echo "Test execution summary:" | ||
| TEST_RESULT_FILES=$(find build -name "TEST-*.xml" 2>/dev/null) | ||
| if [ -n "$TEST_RESULT_FILES" ]; then | ||
| TOTAL_TESTS=$(cat $TEST_RESULT_FILES | grep -o 'tests="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') | ||
| TOTAL_FAILURES=$(cat $TEST_RESULT_FILES | grep -o 'failures="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') | ||
| TOTAL_ERRORS=$(cat $TEST_RESULT_FILES | grep -o 'errors="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') | ||
| echo " Tests: $TOTAL_TESTS | Failures: $TOTAL_FAILURES | Errors: $TOTAL_ERRORS" | ||
| else | ||
| echo " No test result files found" | ||
| fi | ||
| echo "" | ||
| echo "SonarQube configuration (sonar-project.properties):" | ||
| cat sonar-project.properties | ||
| echo "" | ||
| echo "=== Verification Complete ===" | ||
| - name: SonarCloud Scan | ||
| uses: SonarSource/sonarqube-scan-action@v7 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information | ||
| SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} | ||
| SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }} | ||