Skip to content

chore: Fix issue where the source is not available in the coverage report. #40

chore: Fix issue where the source is not available in the coverage report.

chore: Fix issue where the source is not available in the coverage report. #40

Workflow file for this run

name: Combined Coverage Report
on:
push:
branches:
- main
pull_request:
jobs:
coverage:
name: Generate Combined Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
- name: Install dependencies
run: |
dart pub global activate melos
dart pub global activate coverage
dart pub global activate combine_coverage
melos bootstrap
- name: Run tests with coverage for all packages
run: |
# Create directory for combined coverage
mkdir coverage
# Run tests for each package and generate coverage
cd packages
for d in */ ; do
cd "$d"
if [ -f "pubspec.yaml" ]; then
echo "Running tests for $d"
if [[ "$d" == "supabase_flutter/"* ]]; then
flutter test --coverage --concurrency=1
else
# Set up Docker containers based on package
if [[ "$d" == "postgrest/"* ]]; then
cd ../../infra/postgrest
docker compose down
docker compose up -d
cd ../../packages/postgrest
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/postgrest
docker compose down
sleep 5s
cd ../../packages/postgrest
elif [[ "$d" == "gotrue/"* ]]; then
cd ../../infra/gotrue
docker compose down
docker compose up -d
cd ../../packages/gotrue
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/gotrue
docker compose down
sleep 5s
cd ../../packages/gotrue
elif [[ "$d" == "storage_client/"* ]]; then
cd ../../infra/storage_client
docker compose down
docker compose up -d
cd ../../packages/storage_client
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/storage_client
docker compose down
sleep 5s
cd ../../packages/storage_client
else
cd ../../packages/$d
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
fi
fi
fi
cd ..
done
cd ..
- name: Combine coverage reports
run: |
dart pub global run combine_coverage:combine_coverage --repo-path="./" --output-directory="coverage"
- name: Prepare coverage for Coveralls
run: |
# Make sure source file paths are correct in the LCOV file
echo "Original LCOV file contents (first few lines):"
head -n 20 ./coverage/lcov.info
# Check current paths in LCOV file
echo "Original source file paths in LCOV:"
grep -e "^SF:" ./coverage/lcov.info | head -n 10
# First, ensure all paths are correctly pointing to package sources
# This specifically fixes paths for combined package coverage
# Replace paths like "lib/file.dart" with "packages/package_name/lib/file.dart"
cp ./coverage/lcov.info ./coverage/lcov.info.bak
# Extract package names from LCOV
echo "Extracting package names from LCOV..."
PACKAGES=$(grep -e "^SF:" ./coverage/lcov.info | grep -o "packages/[^/]*" | sort -u)
echo "Found packages: $PACKAGES"
# Fix paths that are missing the correct package prefix
echo "Normalizing paths in LCOV file..."
while IFS= read -r line; do
if [[ "$line" =~ ^SF: ]]; then
path="${line#SF:}"
# If the path doesn't start with "packages/" and isn't a relative path
if [[ ! "$path" == packages/* && ! "$path" == ./packages/* && "$path" == lib/* ]]; then
# Look for the right package for this file
for pkg in $PACKAGES; do
pkg_name="${pkg#packages/}"
if grep -q "^SF:$pkg/lib" ./coverage/lcov.info; then
# Add the correct package prefix to the path
echo "SF:$pkg/$path" >> ./coverage/lcov.info.fixed
continue 2
fi
done
# If we can't determine the package, just keep the original line
echo "$line" >> ./coverage/lcov.info.fixed
else
# Path already has package prefix or is relative, keep as is
echo "$line" >> ./coverage/lcov.info.fixed
fi
else
# Non-SF lines, copy as is
echo "$line" >> ./coverage/lcov.info.fixed
fi
done < ./coverage/lcov.info
# Replace the original with the fixed version
mv ./coverage/lcov.info.fixed ./coverage/lcov.info
# Ensure all paths start with ./
sed -i 's|^SF:packages/|SF:./packages/|g' ./coverage/lcov.info
sed -i 's|^SF:\([^.]\)|SF:./\1|g' ./coverage/lcov.info
echo "Final LCOV file contents (first few lines):"
head -n 20 ./coverage/lcov.info
echo "Final source file paths in LCOV:"
grep -e "^SF:" ./coverage/lcov.info | head -n 10
# Verify existence of the referenced source files
echo "Verifying existence of source files..."
for file in $(grep -e "^SF:" ./coverage/lcov.info | sed 's/^SF://' | head -n 10); do
echo "Checking $file: $(test -f "$file" && echo "FOUND" || echo "NOT FOUND")"
done
- name: Upload combined coverage report
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
flag-name: Unit