Skip to content

Test Summary

Test Summary #460

Workflow file for this run

name: Test Summary
on:
workflow_run:
workflows: ["CNPlus CI (Android) App Build"]
types:
- completed
jobs:
test-summary:
name: Generate Test Summary
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'cancelled' }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
path: artifacts
continue-on-error: true
# Debug: Show what artifacts were downloaded
- name: List downloaded artifacts
if: always()
run: |
echo "=== Downloaded Artifacts ==="
ls -la artifacts/ 2>/dev/null || echo "No artifacts directory"
echo ""
echo "=== Directory structure ==="
find artifacts -type d 2>/dev/null | head -20 || echo "No directories found"
# Find and symlink artifacts to predictable paths (artifact names include timestamps)
- name: Setup artifact paths
if: always()
run: |
mkdir -p normalized
# Find unit test results (name: unit-test-results-and-coverage-{datetime})
UNIT_TEST_DIR=$(find artifacts -maxdepth 1 -type d -name "unit-test-results-and-coverage-*" | head -1)
if [ -n "$UNIT_TEST_DIR" ]; then
ln -s "../$UNIT_TEST_DIR" normalized/unit-tests
echo "Found unit tests: $UNIT_TEST_DIR"
else
echo "No unit test results found"
fi
# Find integration test coverage (name: android-test-coverage-report-{datetime})
INTEGRATION_DIR=$(find artifacts -maxdepth 1 -type d -name "android-test-coverage-report-*" | head -1)
if [ -n "$INTEGRATION_DIR" ]; then
ln -s "../$INTEGRATION_DIR" normalized/integration-tests
echo "Found integration tests: $INTEGRATION_DIR"
else
echo "No integration test coverage found"
fi
# Find full coverage reports (name: full-code-coverage-reports-{datetime})
FULL_COVERAGE_DIR=$(find artifacts -maxdepth 1 -type d -name "full-code-coverage-reports-*" | head -1)
if [ -n "$FULL_COVERAGE_DIR" ]; then
ln -s "../$FULL_COVERAGE_DIR" normalized/full-coverage
echo "Found full coverage: $FULL_COVERAGE_DIR"
else
echo "No full coverage reports found"
fi
echo ""
echo "=== Normalized paths ==="
ls -la normalized/
# Find test result XML files
- name: Locate test result files
id: find_results
if: always()
run: |
echo "=== Looking for unit test XML files ==="
UNIT_XML=$(find normalized/unit-tests -name "*.xml" -path "*test-results*" 2>/dev/null | head -5)
echo "$UNIT_XML"
echo ""
echo "=== Looking for integration test XML files ==="
# Integration tests use XmlRunListener output
INTEGRATION_XML=$(find normalized/integration-tests -name "*.xml" 2>/dev/null | head -5)
echo "$INTEGRATION_XML"
# Set outputs for conditional steps
if [ -n "$UNIT_XML" ]; then
echo "has_unit_results=true" >> $GITHUB_OUTPUT
else
echo "has_unit_results=false" >> $GITHUB_OUTPUT
fi
if [ -n "$INTEGRATION_XML" ]; then
echo "has_integration_results=true" >> $GITHUB_OUTPUT
else
echo "has_integration_results=false" >> $GITHUB_OUTPUT
fi
- name: Publish Unit Test Summary
uses: dorny/test-reporter@v2
if: always() && steps.find_results.outputs.has_unit_results == 'true'
with:
name: 'Unit Tests Summary'
path: 'normalized/unit-tests/**/test-results/**/*.xml'
reporter: java-junit
fail-on-error: false
use-actions-summary: true
continue-on-error: true
- name: Publish Integration Test Summary
uses: dorny/test-reporter@v2
if: always() && steps.find_results.outputs.has_integration_results == 'true'
with:
name: 'Integration Tests Summary'
path: 'normalized/integration-tests/**/*.xml'
reporter: java-junit
fail-on-error: false
use-actions-summary: true
continue-on-error: true
# Process and display code coverage from JaCoCo XML reports
- name: Process Code Coverage Summary
if: always()
run: |
echo "## 📊 Code Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Look for JaCoCo XML reports
JACOCO_XML=$(find normalized -name "*.xml" -path "*jacoco*" 2>/dev/null | head -1)
if [ -n "$JACOCO_XML" ] && [ -f "$JACOCO_XML" ]; then
echo "Found JaCoCo report: $JACOCO_XML"
# Extract coverage metrics from XML using grep/sed (no jq needed for XML)
INSTRUCTION_MISSED=$(grep -oP 'type="INSTRUCTION"[^/]*missed="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
INSTRUCTION_COVERED=$(grep -oP 'type="INSTRUCTION"[^/]*covered="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
BRANCH_MISSED=$(grep -oP 'type="BRANCH"[^/]*missed="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
BRANCH_COVERED=$(grep -oP 'type="BRANCH"[^/]*covered="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
LINE_MISSED=$(grep -oP 'type="LINE"[^/]*missed="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
LINE_COVERED=$(grep -oP 'type="LINE"[^/]*covered="\K[0-9]+' "$JACOCO_XML" | head -1 || echo "0")
# Calculate percentages
if [ "$((INSTRUCTION_COVERED + INSTRUCTION_MISSED))" -gt 0 ]; then
INSTRUCTION_PCT=$((100 * INSTRUCTION_COVERED / (INSTRUCTION_COVERED + INSTRUCTION_MISSED)))
else
INSTRUCTION_PCT=0
fi
if [ "$((BRANCH_COVERED + BRANCH_MISSED))" -gt 0 ]; then
BRANCH_PCT=$((100 * BRANCH_COVERED / (BRANCH_COVERED + BRANCH_MISSED)))
else
BRANCH_PCT=0
fi
if [ "$((LINE_COVERED + LINE_MISSED))" -gt 0 ]; then
LINE_PCT=$((100 * LINE_COVERED / (LINE_COVERED + LINE_MISSED)))
else
LINE_PCT=0
fi
echo "| Metric | Covered | Missed | Total | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|--------|---------|--------|-------|----------|" >> $GITHUB_STEP_SUMMARY
echo "| Instructions | $INSTRUCTION_COVERED | $INSTRUCTION_MISSED | $((INSTRUCTION_COVERED + INSTRUCTION_MISSED)) | ${INSTRUCTION_PCT}% |" >> $GITHUB_STEP_SUMMARY
echo "| Branches | $BRANCH_COVERED | $BRANCH_MISSED | $((BRANCH_COVERED + BRANCH_MISSED)) | ${BRANCH_PCT}% |" >> $GITHUB_STEP_SUMMARY
echo "| Lines | $LINE_COVERED | $LINE_MISSED | $((LINE_COVERED + LINE_MISSED)) | ${LINE_PCT}% |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Add badge
if [ "$LINE_PCT" -ge 80 ]; then
COLOR="brightgreen"
elif [ "$LINE_PCT" -ge 60 ]; then
COLOR="yellow"
elif [ "$LINE_PCT" -ge 40 ]; then
COLOR="orange"
else
COLOR="red"
fi
echo "![Line Coverage](https://img.shields.io/badge/Line_Coverage-${LINE_PCT}%25-${COLOR})" >> $GITHUB_STEP_SUMMARY
else
echo "No JaCoCo XML reports found." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports may not have been generated in this run." >> $GITHUB_STEP_SUMMARY
fi
# List available coverage artifacts
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Available Coverage Artifacts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for dir in artifacts/*/; do
dirname=$(basename "$dir")
if [[ "$dirname" == *"coverage"* ]] || [[ "$dirname" == *"test"* ]]; then
echo "- \`$dirname\`" >> $GITHUB_STEP_SUMMARY
fi
done