Skip to content

Update README.md

Update README.md #58

Workflow file for this run

# .github/workflows/test-coverage.yml
name: Update Test Coverage
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: macOS-15
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Use latest available Xcode version
run: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
- name: Resolve Swift Package Dependencies
run: xcodebuild -resolvePackageDependencies
- name: Build Tests
run: |
xcodebuild build \
-project Weather.xcodeproj \
-scheme ExistingSchemeName \
-destination 'platform=iOS Simulator,name=iPhone 16' \
| tee xcodebuild.log
- name: Run tests with coverage
run: |
xcodebuild test \
-project Weather.xcodeproj \
-scheme Weather \
-destination 'platform=iOS Simulator,name=iPhone 16' \
-enableCodeCoverage YES \
-resultBundlePath TestResults.xcresult | tee xcodebuild.log
continue-on-error: true
- name: Debug test failure (if any)
if: failure()
run: |
tail -n 100 xcodebuild.log
- name: Verify coverage data
run: |
if ! [ -d "TestResults.xcresult" ]; then
echo "❌ Test results not found. Check test logs."
exit 1
fi
if ! xcrun xccov view --report TestResults.xcresult > /dev/null 2>&1; then
echo "❌ No coverage data found. Ensure tests are generating coverage."
exit 1
fi
- name: Move coverage.json to repo root
run: |
mv coverage/coverage.json coverage.json
- name: Update README with Test Coverage
run: |
# Extract total coverage and format the percentage to 2 decimals
TOTAL_COVERAGE=$(jq -r '.coveredLines / .executableLines * 100 | round / 1' coverage.json)
# Create badge for total coverage
COVERAGE_BADGE_URL="https://img.shields.io/badge/Total%20Test%20Coverage-${TOTAL_COVERAGE}%25-green?style=flat&logo=swift&logoColor=white"
# Generate coverage section content
echo "## Test Coverage" > coverage_section.md
echo "" >> coverage_section.md
echo "### 📊 General Coverage" >> coverage_section.md
echo "[![Test Coverage]($COVERAGE_BADGE_URL)](https://github.com/mrugama/Weather/actions)" >> coverage_section.md
echo "" >> coverage_section.md
echo "---" >> coverage_section.md
echo "### 📄 File-wise Coverage Breakdown" >> coverage_section.md
echo "| File | Covered Lines | Executable Lines | Coverage |" >> coverage_section.md
echo "|------|--------------|-----------------|----------|" >> coverage_section.md
# Loop through each file in coverage.json and add to table
jq -r '.targets[].files[] | "| \(.name) | \(.coveredLines) | \(.executableLines) | \((.lineCoverage * 100) | round)%"' coverage.json >> coverage_section.md
echo "---" >> coverage_section.md
echo "" >> coverage_section.md
# Remove the entire "Test Coverage" section (including content) from README
awk '
/^## Test Coverage$/,/^## / { if (!/^## /) next }
{ print }' README.md > README.tmp
# Add the new "Test Coverage" section content from coverage_section.md
cat coverage_section.md >> README.tmp
# Move the updated file back to README.md
mv README.tmp README.md
# Clean up temporary file
rm coverage_section.md
- name: Commit and push coverage report
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
git config --global user.name "mrugama"
git config --global user.email "mrugama@gmail.com"
git remote set-url origin https://mrugama:${GH_PAT}@github.com/mrugama/Weather.git
git add coverage.json
git add README.md
git commit -m "Update test coverage report" || exit 0
git push origin HEAD:master