Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,76 @@ jobs:
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