Skip to content

Commit 8c45525

Browse files
committed
check source file location within workflow
1 parent 86f5f95 commit 8c45525

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

.github/workflows/coverage.yml

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313

1414
steps:
1515
- uses: actions/checkout@v4
16-
with:
17-
fetch-depth: 0 # Fetch all history for proper source code mapping
1816

1917
- uses: subosito/flutter-action@v2
2018
with:
@@ -94,27 +92,69 @@ jobs:
9492
- name: Prepare coverage for Coveralls
9593
run: |
9694
# Make sure source file paths are correct in the LCOV file
97-
echo "LCOV file contents (first few lines):"
95+
echo "Original LCOV file contents (first few lines):"
9896
head -n 20 ./coverage/lcov.info
9997
100-
# Check if source files exist in the expected locations
101-
grep -A 1 "SF:" ./coverage/lcov.info | head -n 10
98+
# Check current paths in LCOV file
99+
echo "Original source file paths in LCOV:"
100+
grep -e "^SF:" ./coverage/lcov.info | head -n 10
101+
102+
# First, ensure all paths are correctly pointing to package sources
103+
# This specifically fixes paths for combined package coverage
104+
# Replace paths like "lib/file.dart" with "packages/package_name/lib/file.dart"
105+
cp ./coverage/lcov.info ./coverage/lcov.info.bak
102106
103-
# Verify file paths in the repository
104-
find . -type f -name "*.dart" | head -n 10
107+
# Extract package names from LCOV
108+
echo "Extracting package names from LCOV..."
109+
PACKAGES=$(grep -e "^SF:" ./coverage/lcov.info | grep -o "packages/[^/]*" | sort -u)
110+
echo "Found packages: $PACKAGES"
105111
106-
# If needed, fix paths by ensuring they're relative to the workspace instead of absolute
107-
# This pattern replaces absolute paths and ensures paths are relative to repo root
108-
sed -i -E 's|SF:(/[^/]+)*?/packages/|SF:packages/|g' ./coverage/lcov.info
112+
# Fix paths that are missing the correct package prefix
113+
echo "Normalizing paths in LCOV file..."
114+
while IFS= read -r line; do
115+
if [[ "$line" =~ ^SF: ]]; then
116+
path="${line#SF:}"
117+
# If the path doesn't start with "packages/" and isn't a relative path
118+
if [[ ! "$path" == packages/* && ! "$path" == ./packages/* && "$path" == lib/* ]]; then
119+
# Look for the right package for this file
120+
for pkg in $PACKAGES; do
121+
pkg_name="${pkg#packages/}"
122+
if grep -q "^SF:$pkg/lib" ./coverage/lcov.info; then
123+
# Add the correct package prefix to the path
124+
echo "SF:$pkg/$path" >> ./coverage/lcov.info.fixed
125+
continue 2
126+
fi
127+
done
128+
# If we can't determine the package, just keep the original line
129+
echo "$line" >> ./coverage/lcov.info.fixed
130+
else
131+
# Path already has package prefix or is relative, keep as is
132+
echo "$line" >> ./coverage/lcov.info.fixed
133+
fi
134+
else
135+
# Non-SF lines, copy as is
136+
echo "$line" >> ./coverage/lcov.info.fixed
137+
fi
138+
done < ./coverage/lcov.info
109139
110-
echo "Updated LCOV file contents (first few lines):"
140+
# Replace the original with the fixed version
141+
mv ./coverage/lcov.info.fixed ./coverage/lcov.info
142+
143+
# Ensure all paths start with ./
144+
sed -i 's|^SF:packages/|SF:./packages/|g' ./coverage/lcov.info
145+
sed -i 's|^SF:\([^.]\)|SF:./\1|g' ./coverage/lcov.info
146+
147+
echo "Final LCOV file contents (first few lines):"
111148
head -n 20 ./coverage/lcov.info
112149
113-
# Create a list of source files that are referenced in the LCOV file
114-
echo "Creating list of source files referenced in LCOV"
115-
grep "SF:" ./coverage/lcov.info | sed 's/SF://' | sort > source_files.txt
116-
echo "First 10 source files referenced:"
117-
head -n 10 source_files.txt
150+
echo "Final source file paths in LCOV:"
151+
grep -e "^SF:" ./coverage/lcov.info | head -n 10
152+
153+
# Verify existence of the referenced source files
154+
echo "Verifying existence of source files..."
155+
for file in $(grep -e "^SF:" ./coverage/lcov.info | sed 's/^SF://' | head -n 10); do
156+
echo "Checking $file: $(test -f "$file" && echo "FOUND" || echo "NOT FOUND")"
157+
done
118158
119159
- name: Upload combined coverage report
120160
uses: coverallsapp/github-action@v2

0 commit comments

Comments
 (0)