|
1 | 1 | name: SonarCloud Analysis |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - development |
| 8 | + - '*_baseline' |
4 | 9 | pull_request: |
5 | 10 | branches: |
6 | 11 | - '*' |
@@ -38,114 +43,101 @@ jobs: |
38 | 43 | - name: Build project and run tests with coverage |
39 | 44 | run: | |
40 | 45 | # Build the project |
41 | | - ./gradlew assembleDebug --stacktrace |
42 | | -
|
43 | | - # Run tests with coverage - allow test failures |
44 | | - ./gradlew testDebugUnitTest jacocoTestReport --stacktrace |
45 | | - TEST_RESULT=$? |
46 | | - if [ $TEST_RESULT -ne 0 ]; then |
47 | | - echo "Some tests failed, but continuing to check for coverage data..." |
48 | | - # Even if tests fail, JaCoCo should generate a report with partial coverage |
49 | | - # from the tests that did pass |
50 | | - fi |
51 | | -
|
52 | | - - name: Prepare class files for SonarQube analysis |
53 | | - run: | |
54 | | - echo "Searching for compiled class files..." |
55 | | -
|
56 | | - # Create the target directory |
57 | | - mkdir -p build/intermediates/runtime_library_classes_dir/debug |
58 | | -
|
59 | | - # Find all directories containing class files with better patterns |
60 | | - CLASS_DIRS=$(find build -name "*.class" -type f -exec dirname {} \; | sort -u | grep -E "(javac|kotlin-classes|runtime_library)" | head -10) |
61 | | -
|
62 | | - if [ -z "$CLASS_DIRS" ]; then |
63 | | - echo "WARNING: No class files found in the build directory!" |
64 | | - echo "Searching in all build subdirectories..." |
65 | | - find build -name "*.class" -type f | head -20 |
| 46 | + ./gradlew assembleDebug |
| 47 | +
|
| 48 | + # Run tests - continue even if some tests fail |
| 49 | + ./gradlew testDebugUnitTest || echo "Some tests failed, but continuing to generate coverage report..." |
| 50 | + |
| 51 | + # Generate JaCoCo aggregate report separately (ensures it runs even if tests failed) |
| 52 | + ./gradlew jacocoRootReport |
| 53 | +
|
| 54 | + # Log report location for debugging |
| 55 | + REPORT_PATH="build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml" |
| 56 | + if [ -f "$REPORT_PATH" ]; then |
| 57 | + echo "✓ JaCoCo report generated at: $REPORT_PATH ($(wc -c < "$REPORT_PATH") bytes)" |
66 | 58 | else |
67 | | - echo "Found class files in the following directories:" |
68 | | - echo "$CLASS_DIRS" |
69 | | -
|
70 | | - # Copy classes from all relevant directories, not just the first one |
71 | | - for CLASS_DIR in $CLASS_DIRS; do |
72 | | - if [ -d "$CLASS_DIR" ] && [ "$(find "$CLASS_DIR" -name "*.class" | wc -l)" -gt 0 ]; then |
73 | | - echo "Copying classes from $CLASS_DIR" |
74 | | - cp -r "$CLASS_DIR"/* build/intermediates/runtime_library_classes_dir/debug/ 2>/dev/null || echo "Failed to copy from $CLASS_DIR" |
75 | | - fi |
76 | | - done |
77 | | -
|
78 | | - # Verify the target directory now has class files |
79 | | - CLASS_COUNT=$(find build/intermediates/runtime_library_classes_dir/debug -name "*.class" | wc -l) |
80 | | - echo "Target directory now contains $CLASS_COUNT class files" |
| 59 | + echo "✗ JaCoCo report was NOT generated at: $REPORT_PATH" |
81 | 60 | fi |
82 | 61 |
|
83 | | - # Update sonar-project.properties with all found class directories |
84 | | - echo "" >> sonar-project.properties |
85 | | - echo "# Additional binary paths found during build" >> sonar-project.properties |
86 | | - if [ -n "$CLASS_DIRS" ]; then |
87 | | - # Convert newlines to commas for sonar.java.binaries |
88 | | - BINARY_PATHS=$(echo "$CLASS_DIRS" | tr '\n' ',' | sed 's/,$//') |
89 | | - echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug,$BINARY_PATHS" >> sonar-project.properties |
| 62 | + - name: Verify class files and coverage data for SonarQube analysis |
| 63 | + run: | |
| 64 | + echo "=== Verifying Build Artifacts for SonarQube ===" |
| 65 | + echo "" |
| 66 | + |
| 67 | + # Dynamically get modules from settings.gradle (extract module names from "include ':modulename'" lines) |
| 68 | + MODULES=$(grep "^include" settings.gradle | cut -d"'" -f2 | cut -d":" -f2 | tr '\n' ' ') |
| 69 | + echo "Detected modules: $MODULES" |
| 70 | + echo "" |
| 71 | + |
| 72 | + echo "Checking compiled class files for each module:" |
| 73 | + for module in $MODULES; do |
| 74 | + MODULE_CLASSES_DIR="${module}/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" |
| 75 | + if [ -d "$MODULE_CLASSES_DIR" ]; then |
| 76 | + CLASS_COUNT=$(find "$MODULE_CLASSES_DIR" -name "*.class" | wc -l) |
| 77 | + echo " ✓ ${module}: Found $CLASS_COUNT class files in $MODULE_CLASSES_DIR" |
| 78 | + else |
| 79 | + echo " ✗ ${module}: Class directory not found: $MODULE_CLASSES_DIR" |
| 80 | + fi |
| 81 | + done |
| 82 | + |
| 83 | + echo "" |
| 84 | + echo "Checking JaCoCo coverage report:" |
| 85 | + if [ -f build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml ]; then |
| 86 | + REPORT_SIZE=$(wc -c < build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml) |
| 87 | + PACKAGE_COUNT=$(grep -c "<package" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") |
| 88 | + CLASS_COUNT=$(grep -c "<class" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") |
| 89 | + LINE_COUNT=$(grep -c "<line" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") |
| 90 | + COVERED_LINES=$(grep -c 'ci="1"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0") |
| 91 | + |
| 92 | + echo " ✓ JaCoCo report found: build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml" |
| 93 | + echo " - Size: $REPORT_SIZE bytes" |
| 94 | + echo " - Packages: $PACKAGE_COUNT" |
| 95 | + echo " - Classes: $CLASS_COUNT" |
| 96 | + echo " - Lines: $LINE_COUNT" |
| 97 | + echo " - Covered lines: $COVERED_LINES" |
| 98 | + |
| 99 | + # Check if events module coverage is present |
| 100 | + if grep -q 'package name="io/harness/events"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml; then |
| 101 | + echo " ✓ Events module (io/harness/events) coverage found in report" |
| 102 | + else |
| 103 | + echo " ✗ WARNING: Events module coverage NOT found in report" |
| 104 | + fi |
90 | 105 | else |
91 | | - echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug" >> sonar-project.properties |
| 106 | + echo " ✗ JaCoCo report file not found" |
92 | 107 | fi |
93 | | -
|
94 | | - echo "Checking for JaCoCo report files..." |
95 | | - find build -name "*.xml" | grep jacoco || echo "No JaCoCo XML files found" |
96 | | - find build -name "*.exec" | grep jacoco || echo "No JaCoCo exec files found" |
97 | | -
|
98 | | - echo "Contents of JaCoCo report directory:" |
99 | | - ls -la build/reports/jacoco/jacocoTestReport/ || echo "Directory not found" |
100 | | -
|
| 108 | + |
| 109 | + echo "" |
| 110 | + echo "Checking JaCoCo execution data for each module:" |
| 111 | + for module in $MODULES; do |
| 112 | + EXEC_FILE="${module}/build/jacoco/testDebugUnitTest.exec" |
| 113 | + if [ -f "$EXEC_FILE" ]; then |
| 114 | + EXEC_SIZE=$(wc -c < "$EXEC_FILE") |
| 115 | + echo " ✓ ${module}: Found execution data ($EXEC_SIZE bytes) in $EXEC_FILE" |
| 116 | + else |
| 117 | + echo " ✗ ${module}: Execution data not found: $EXEC_FILE" |
| 118 | + fi |
| 119 | + done |
| 120 | + |
101 | 121 | echo "" |
102 | | - echo "Checking test execution results:" |
| 122 | + echo "Test execution summary:" |
103 | 123 | TEST_RESULT_FILES=$(find build -name "TEST-*.xml" 2>/dev/null) |
104 | 124 | if [ -n "$TEST_RESULT_FILES" ]; then |
105 | | - echo "Found test result files:" |
106 | | - echo "$TEST_RESULT_FILES" |
107 | | - # Count total tests, failures, errors |
108 | 125 | TOTAL_TESTS=$(cat $TEST_RESULT_FILES | grep -o 'tests="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') |
109 | 126 | TOTAL_FAILURES=$(cat $TEST_RESULT_FILES | grep -o 'failures="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') |
110 | 127 | TOTAL_ERRORS=$(cat $TEST_RESULT_FILES | grep -o 'errors="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}') |
111 | | - echo "Test summary: $TOTAL_TESTS tests, $TOTAL_FAILURES failures, $TOTAL_ERRORS errors" |
112 | | - else |
113 | | - echo "No test result files found" |
114 | | - fi |
115 | | -
|
116 | | - echo "" |
117 | | - echo "Checking JaCoCo report content:" |
118 | | - if [ -f build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml ]; then |
119 | | - echo "Report file size: $(wc -c < build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml) bytes" |
120 | | - echo "First 500 chars of report:" |
121 | | - head -c 500 build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml |
122 | | - echo "" |
123 | | - echo "" |
124 | | - echo "Counting coverage elements:" |
125 | | - grep -c "<package" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No packages found" |
126 | | - grep -c "<class" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No classes found" |
127 | | - grep -c "<method" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No methods found" |
128 | | - grep -c "<line" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No lines found" |
129 | | - grep -c 'ci="1"' build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No covered lines found" |
| 128 | + echo " Tests: $TOTAL_TESTS | Failures: $TOTAL_FAILURES | Errors: $TOTAL_ERRORS" |
130 | 129 | else |
131 | | - echo "JaCoCo report file not found" |
| 130 | + echo " No test result files found" |
132 | 131 | fi |
133 | | -
|
134 | | - echo "" |
135 | | - echo "Checking binary directories specified in sonar-project.properties:" |
136 | | - echo "build/intermediates/runtime_library_classes_dir/debug:" |
137 | | - ls -la build/intermediates/runtime_library_classes_dir/debug || echo "Directory not found" |
138 | | -
|
| 132 | + |
139 | 133 | echo "" |
140 | | - echo "Checking all available class directories:" |
141 | | - find build -path "*/build/*" -name "*.class" | head -n 10 || echo "No class files found" |
142 | | -
|
143 | | - echo "" |
144 | | - echo "Final sonar-project.properties content:" |
| 134 | + echo "SonarQube configuration (sonar-project.properties):" |
145 | 135 | cat sonar-project.properties |
| 136 | + echo "" |
| 137 | + echo "=== Verification Complete ===" |
146 | 138 |
|
147 | 139 | - name: SonarCloud Scan |
148 | | - uses: SonarSource/sonarqube-scan-action@v6 |
| 140 | + uses: SonarSource/sonarqube-scan-action@v7 |
149 | 141 | env: |
150 | 142 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information |
151 | 143 | SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} |
|
0 commit comments