Skip to content

Commit e82525d

Browse files
committed
WIP
1 parent bd629de commit e82525d

File tree

1 file changed

+54
-120
lines changed

1 file changed

+54
-120
lines changed

.github/workflows/sonarqube.yml

Lines changed: 54 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
with:
3434
distribution: 'temurin'
3535
java-version: 17
36-
cache: 'gradle'
3736

3837
- name: Gradle cache
3938
uses: gradle/actions/setup-gradle@v3
@@ -196,129 +195,65 @@ jobs:
196195
api-level: 28
197196
profile: Galaxy Nexus
198197
script: |
199-
# Run instrumented tests with coverage - allow test failures
200-
# Use a more direct approach to ensure coverage is enabled
201-
./gradlew assembleDebugAndroidTest
202-
203-
# First, let's determine the correct test package name
204-
echo "\n[DEBUG] Listing all available instrumentation packages:"
205-
adb shell pm list instrumentation
206-
207-
TEST_PACKAGE=$(adb shell pm list instrumentation | grep split | cut -d' ' -f1 | cut -d: -f2)
208-
echo "\n[DEBUG] Found test instrumentation package: $TEST_PACKAGE"
209-
210-
# Check if the test APK is installed properly
211-
echo "\n[DEBUG] Checking installed packages:"
212-
adb shell pm list packages | grep split
213-
214-
# Verify test class exists
215-
echo "\n[DEBUG] Checking if test class exists:"
216-
./gradlew -q listTestClasses | grep DatabaseInitializationTest || echo "Test class not found in Gradle test classes"
217-
218-
# Run only a single test class with coverage explicitly enabled
219-
echo "\n[DEBUG] Running instrumentation with explicit coverage flag:"
220-
adb shell "am instrument -w -e coverage true -e class tests.database.DatabaseInitializationTest $TEST_PACKAGE"
221-
TEST_RESULT=$?
222-
if [ $TEST_RESULT -ne 0 ]; then
223-
echo "Some instrumented tests failed, but continuing to check for coverage data..."
224-
else
225-
echo "\n[DEBUG] Instrumentation completed successfully"
226-
fi
227-
228-
# Create directory for coverage files
198+
# Ensure the app and test app are built
199+
./gradlew assembleDebug assembleDebugAndroidTest --stacktrace
200+
201+
echo "Starting instrumented tests with coverage..."
202+
# Run connectedDebugAndroidTest, explicitly telling it where to save the coverage file on the emulator.
203+
# This aligns with how AGP handles coverage when this property is set.
204+
./gradlew connectedDebugAndroidTest --stacktrace -Pandroid.testInstrumentationRunnerArguments.coverage=true -Pandroid.testInstrumentationRunnerArguments.coverageFile="/sdcard/coverage.ec"
205+
TEST_RUN_RESULT=$?
206+
echo "Instrumented test run finished with Gradle task result: $TEST_RUN_RESULT"
207+
208+
# Create the target directory for the pulled coverage file
229209
mkdir -p build/outputs/code_coverage/debugAndroidTest/connected/
230-
231-
# Try to find and pull coverage files from various possible locations
232-
echo "\n[DEBUG] Searching for coverage files..."
233-
234-
# Check if coverage is enabled in the app manifest
235-
echo "\n[DEBUG] Checking test AndroidManifest.xml for coverage settings:"
236-
adb shell pm dump $TEST_PACKAGE | grep -i coverage
237-
238-
# Check for files in external storage
239-
echo "\n[DEBUG] Checking external storage for coverage files:"
240-
adb shell ls -la /sdcard/ | grep -i coverage || echo "No coverage files found in /sdcard/"
241-
242-
# Check app-specific data directory - try both package names
243-
echo "\n[DEBUG] Checking app-specific data directory for coverage files:"
244-
APP_PACKAGE=$(adb shell pm list packages | grep split | cut -d: -f2 | head -1)
245-
echo "\n[DEBUG] App package name: $APP_PACKAGE"
246-
247-
# Try with the detected app package
248-
echo "\n[DEBUG] Searching in /data/data/$APP_PACKAGE/:"
249-
adb shell run-as $APP_PACKAGE find /data/data/$APP_PACKAGE -name "*.ec" | while read -r file; do
250-
echo "Found coverage file: $file"
251-
filename=$(basename "$file")
252-
adb shell run-as $APP_PACKAGE cat "$file" > "build/outputs/code_coverage/debugAndroidTest/connected/$filename"
253-
echo "Pulled coverage file to build/outputs/code_coverage/debugAndroidTest/connected/$filename"
254-
done
255-
256-
# Also try with the hardcoded package name as fallback
257-
echo "\n[DEBUG] Searching in /data/data/io.split.android.android_client/:"
258-
adb shell run-as io.split.android.android_client find /data/data/io.split.android.android_client -name "*.ec" | while read -r file; do
259-
echo "Found coverage file: $file"
260-
filename=$(basename "$file")
261-
adb shell run-as io.split.android.android_client cat "$file" > "build/outputs/code_coverage/debugAndroidTest/connected/$filename"
262-
echo "Pulled coverage file to build/outputs/code_coverage/debugAndroidTest/connected/$filename"
263-
done
264-
265-
# Also check sdcard location
266-
echo "\n[DEBUG] Checking /sdcard/ location:"
267-
adb pull /sdcard/coverage.ec build/outputs/code_coverage/debugAndroidTest/connected/ || echo "No coverage file at /sdcard/coverage.ec"
268-
269-
# Try alternative locations
270-
echo "\n[DEBUG] Checking alternative locations for coverage files:"
271-
adb pull /data/local/tmp/coverage.ec build/outputs/code_coverage/debugAndroidTest/connected/ || echo "No coverage file at /data/local/tmp/coverage.ec"
272-
273-
# List all coverage files to verify
274-
echo "\n[DEBUG] Listing all found coverage files:"
275-
find build -name "*.ec" -o -name "*.exec"
276-
277-
# Run the JaCoCo report task with debug info
278-
echo "\n[DEBUG] Running JaCoCo Android test report task with debug info:"
279-
./gradlew jacocoAndroidTestReport --debug > jacoco_debug.log
280-
REPORT_RESULT=$?
281-
282-
# Save the important parts of the debug log
283-
echo "\n[DEBUG] Extracting coverage-related info from debug log:"
284-
grep -A 10 -B 2 "JaCoCo" jacoco_debug.log > jacoco_important.log || echo "No JaCoCo info found in debug log"
285-
grep -A 5 -B 2 "coverage" jacoco_debug.log >> jacoco_important.log || echo "No coverage info found in debug log"
286-
grep -A 3 -B 1 "exec" jacoco_debug.log >> jacoco_important.log || echo "No exec info found in debug log"
287-
grep -A 3 -B 1 "ec" jacoco_debug.log >> jacoco_important.log || echo "No .ec info found in debug log"
288-
289-
echo "\n[DEBUG] Important JaCoCo debug info:"
290-
cat jacoco_important.log
291-
292-
if [ $REPORT_RESULT -ne 0 ]; then
293-
echo "\n[DEBUG] Failed to generate Android test coverage report, but continuing..."
294-
echo "\n[DEBUG] Last 20 lines of debug log:"
295-
tail -20 jacoco_debug.log
296-
else
297-
echo "\n[DEBUG] JaCoCo Android test report generated successfully"
210+
211+
echo "Attempting to pull coverage file from /sdcard/coverage.ec on emulator $AVD_NAME"
212+
adb pull /sdcard/coverage.ec build/outputs/code_coverage/debugAndroidTest/connected/$AVD_NAME-coverage.ec
213+
PULL_RESULT=$?
214+
echo "ADB pull command finished with result: $PULL_RESULT"
215+
216+
# Define the expected path for the pulled coverage file
217+
PULLED_COVERAGE_FILE="build/outputs/code_coverage/debugAndroidTest/connected/$AVD_NAME-coverage.ec"
218+
219+
# Verification
220+
SUCCESS=true
221+
if [ $TEST_RUN_RESULT -ne 0 ]; then
222+
echo "ERROR: Instrumented tests Gradle task failed (Result: $TEST_RUN_RESULT)."
223+
SUCCESS=false
298224
fi
299-
300-
# Check if the Android test report was generated with content
301-
if [ -f build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml ]; then
302-
# Use stat command compatible with both Linux and macOS
303-
if [[ "$(uname)" == "Darwin" ]]; then
304-
# macOS syntax
305-
REPORT_SIZE=$(stat -f%z build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml)
306-
else
307-
# Linux syntax
308-
REPORT_SIZE=$(stat -c%s build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml)
309-
fi
310-
311-
echo "Android test JaCoCo report size: $REPORT_SIZE bytes"
312-
313-
if [ "$REPORT_SIZE" -lt 1000 ]; then
314-
echo "WARNING: Android test JaCoCo report is too small, likely empty"
315-
else
316-
echo "Android test JaCoCo report generated successfully"
225+
226+
if [ $PULL_RESULT -ne 0 ]; then
227+
echo "ERROR: adb pull command failed to retrieve coverage file (Result: $PULL_RESULT)."
228+
SUCCESS=false
229+
fi
230+
231+
if [ ! -f "$PULLED_COVERAGE_FILE" ]; then
232+
echo "ERROR: Coverage file was NOT found at $PULLED_COVERAGE_FILE after adb pull."
233+
SUCCESS=false
234+
else
235+
echo "Coverage file found at $PULLED_COVERAGE_FILE."
236+
ls -l "$PULLED_COVERAGE_FILE"
237+
# Optional: Check file size (e.g., if less than a few hundred bytes, it might be empty/invalid)
238+
COVERAGE_FILE_SIZE=$(stat -c%s "$PULLED_COVERAGE_FILE")
239+
echo "Coverage file size: $COVERAGE_FILE_SIZE bytes."
240+
if [ "$COVERAGE_FILE_SIZE" -lt 100 ]; then # Adjust threshold as needed
241+
echo "WARNING: Pulled coverage file is very small, possibly empty or invalid."
242+
# Depending on strictness, you might set SUCCESS=false here too
317243
fi
244+
fi
245+
246+
if [ "$SUCCESS" = false ]; then
247+
echo "---------------------------------------------------------------------"
248+
echo "DIAGNOSTICS: Instrumented test coverage collection failed."
249+
echo "Listing /sdcard/ on emulator to check if coverage.ec was created there:"
250+
adb shell ls -l /sdcard/
251+
echo "---------------------------------------------------------------------"
252+
echo "Exiting with error."
253+
exit 1
318254
else
319-
echo "WARNING: Android test JaCoCo report file not found"
255+
echo "Instrumented test coverage collection appears successful."
320256
fi
321-
continue-on-error: true
322257
323258
- name: Generate combined coverage report
324259
run: |
@@ -355,7 +290,6 @@ jobs:
355290
mkdir -p build/reports/jacoco/jacocoCombinedReport/
356291
cp build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml build/reports/jacoco/jacocoCombinedReport/jacocoCombinedReport.xml
357292
fi
358-
continue-on-error: true
359293
360294
- name: Check combined coverage report
361295
run: |

0 commit comments

Comments
 (0)