|
13 | 13 |
|
14 | 14 | steps: |
15 | 15 | - uses: actions/checkout@v4 |
16 | | - with: |
17 | | - fetch-depth: 0 # Fetch all history for proper source code mapping |
18 | 16 |
|
19 | 17 | - uses: subosito/flutter-action@v2 |
20 | 18 | with: |
@@ -94,27 +92,69 @@ jobs: |
94 | 92 | - name: Prepare coverage for Coveralls |
95 | 93 | run: | |
96 | 94 | # 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):" |
98 | 96 | head -n 20 ./coverage/lcov.info |
99 | 97 | |
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 |
102 | 106 | |
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" |
105 | 111 | |
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 |
109 | 139 | |
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):" |
111 | 148 | head -n 20 ./coverage/lcov.info |
112 | 149 | |
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 |
118 | 158 | |
119 | 159 | - name: Upload combined coverage report |
120 | 160 | uses: coverallsapp/github-action@v2 |
|
0 commit comments