-
Notifications
You must be signed in to change notification settings - Fork 7
147 lines (127 loc) · 6.1 KB
/
sonarqube.yml
File metadata and controls
147 lines (127 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 }}