@@ -249,40 +249,130 @@ jobs:
249249
250250 - name : Download coverage XML from ADO
251251 run : |
252- # Download the Cobertura XML directly instead of HTML
252+ # Download the Cobertura XML directly from the CodeCoverageReport job
253253 BUILD_ID=${{ env.BUILD_ID }}
254254 ARTIFACTS_URL="https://dev.azure.com/SqlClientDrivers/public/_apis/build/builds/$BUILD_ID/artifacts?api-version=7.1-preview.5"
255255
256- # Find and download coverage.xml
256+ echo "📥 Fetching artifacts for build $BUILD_ID to find coverage files..."
257+
258+ # Fetch artifacts with error handling
257259 ARTIFACTS_RESPONSE=$(curl -s "$ARTIFACTS_URL")
258- COVERAGE_XML_ARTIFACT=$(echo "$ARTIFACTS_RESPONSE" | jq -r '.value[]? | select(.name | test("coverage")) | .resource.downloadUrl // empty' 2>/dev/null)
259260
260- if [[ -n "$COVERAGE_XML_ARTIFACT" ]]; then
261- curl -L "$COVERAGE_XML_ARTIFACT" -o coverage-artifacts.zip
262- unzip -q coverage-artifacts.zip
263- find . -name "coverage*.xml" -exec cp {} ./coverage.xml \;
261+ # Check if response is valid JSON
262+ if ! echo "$ARTIFACTS_RESPONSE" | jq . >/dev/null 2>&1; then
263+ echo "❌ Invalid JSON response from artifacts API"
264+ echo "Response received: $ARTIFACTS_RESPONSE"
265+ exit 1
266+ fi
267+
268+ echo "🔍 Available artifacts:"
269+ echo "$ARTIFACTS_RESPONSE" | jq -r '.value[]?.name // "No artifacts found"'
270+
271+ # Look for the unified coverage artifact from CodeCoverageReport job
272+ COVERAGE_XML_ARTIFACT=$(echo "$ARTIFACTS_RESPONSE" | jq -r '.value[]? | select(.name | test("unified-coverage|Code Coverage Report|coverage")) | .resource.downloadUrl // empty' 2>/dev/null | head -1)
273+
274+ if [[ -n "$COVERAGE_XML_ARTIFACT" && "$COVERAGE_XML_ARTIFACT" != "null" && "$COVERAGE_XML_ARTIFACT" != "empty" ]]; then
275+ echo "📊 Downloading coverage artifact from: $COVERAGE_XML_ARTIFACT"
276+ if ! curl -L "$COVERAGE_XML_ARTIFACT" -o coverage-artifacts.zip --fail --silent; then
277+ echo "❌ Failed to download coverage artifacts"
278+ exit 1
279+ fi
280+
281+ if ! unzip -q coverage-artifacts.zip; then
282+ echo "❌ Failed to extract coverage artifacts"
283+ exit 1
284+ fi
285+
286+ echo "🔍 Looking for coverage XML files in extracted artifacts..."
287+ find . -name "*.xml" -type f | head -10
288+
289+ # Look for the main coverage.xml file in unified-coverage directory or any coverage XML
290+ if [[ -f "unified-coverage/coverage.xml" ]]; then
291+ echo "✅ Found unified coverage file at unified-coverage/coverage.xml"
292+ cp "unified-coverage/coverage.xml" ./coverage.xml
293+ elif [[ -f "coverage.xml" ]]; then
294+ echo "✅ Found coverage.xml in root directory"
295+ # Already in the right place
296+ else
297+ # Try to find any coverage XML file
298+ COVERAGE_FILE=$(find . -name "*coverage*.xml" -type f | head -1)
299+ if [[ -n "$COVERAGE_FILE" ]]; then
300+ echo "✅ Found coverage file: $COVERAGE_FILE"
301+ cp "$COVERAGE_FILE" ./coverage.xml
302+ else
303+ echo "❌ No coverage XML file found in artifacts"
304+ echo "Available files:"
305+ find . -name "*.xml" -type f
306+ exit 1
307+ fi
308+ fi
309+
310+ echo "✅ Coverage XML file is ready at ./coverage.xml"
311+ ls -la ./coverage.xml
312+ else
313+ echo "❌ Could not find coverage artifacts"
314+ echo "This indicates the Azure DevOps CodeCoverageReport job may not have run successfully"
315+ exit 1
264316 fi
265317
266318 - name : Generate patch coverage report
267319 run : |
268- # Install diff-cover and jq
320+ # Install dependencies
269321 pip install diff-cover jq
270- # Generate diff coverage report comparing against main
322+ sudo apt-get update && sudo apt-get install -y libxml2-utils
323+
324+ # Verify coverage.xml exists before proceeding
325+ if [[ ! -f coverage.xml ]]; then
326+ echo "❌ coverage.xml not found in current directory"
327+ echo "Available files:"
328+ ls -la | head -20
329+ exit 1
330+ fi
331+
332+ echo "✅ coverage.xml found, size: $(wc -c < coverage.xml) bytes"
333+ echo "🔍 Coverage file preview (first 10 lines):"
334+ head -10 coverage.xml
335+
336+ # Generate diff coverage report using the new command format
337+ echo "🚀 Generating patch coverage report..."
338+
339+ # Use the new format for diff-cover commands
271340 diff-cover coverage.xml \
272341 --compare-branch=origin/main \
273- --html-report=patch-coverage.html \
274- --json-report=patch-coverage.json \
275- --markdown-report=patch-coverage.md
342+ --format html:patch-coverage.html \
343+ --format json:patch-coverage.json \
344+ --format markdown:patch-coverage.md || {
345+ echo "❌ diff-cover failed with exit code $?"
346+ echo "Checking if coverage.xml is valid XML..."
347+ if ! xmllint --noout coverage.xml 2>/dev/null; then
348+ echo "❌ coverage.xml is not valid XML"
349+ echo "First 50 lines of coverage.xml:"
350+ head -50 coverage.xml
351+ else
352+ echo "✅ coverage.xml is valid XML"
353+ fi
354+ exit 1
355+ }
276356
277357 # Extract patch coverage percentage
278- PATCH_COVERAGE=$(jq -r '.total_percent_covered // "N/A"' patch-coverage.json)
279- echo "PATCH_COVERAGE_PCT=${PATCH_COVERAGE}%" >> $GITHUB_ENV
358+ if [[ -f patch-coverage.json ]]; then
359+ PATCH_COVERAGE=$(jq -r '.total_percent_covered // "N/A"' patch-coverage.json)
360+ echo "PATCH_COVERAGE_PCT=${PATCH_COVERAGE}%" >> $GITHUB_ENV
361+ echo "✅ Patch coverage: ${PATCH_COVERAGE}%"
362+ else
363+ echo "⚠️ patch-coverage.json not generated, setting default"
364+ echo "PATCH_COVERAGE_PCT=N/A" >> $GITHUB_ENV
365+ fi
280366
281367 # Extract summary for comment
282368 if [[ -f patch-coverage.md ]]; then
283369 echo "PATCH_COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV
284370 cat patch-coverage.md >> $GITHUB_ENV
285371 echo "EOF" >> $GITHUB_ENV
372+ echo "✅ Patch coverage markdown summary ready"
373+ else
374+ echo "⚠️ patch-coverage.md not generated"
375+ echo "PATCH_COVERAGE_SUMMARY=Patch coverage report could not be generated." >> $GITHUB_ENV
286376 fi
287377
288378 - name : Comment coverage summary on PR
0 commit comments