Skip to content

made readme more concise #3

made readme more concise

made readme more concise #3

name: Update Coverage Badge
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
coverage-badge:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: npm run test:coverage
- name: Generate coverage badge
run: |
# Extract coverage percentage from lcov.info
COVERAGE=$(cat coverage/lcov.info | grep -E "SF:.+\.ts$" | wc -l)
if [ $COVERAGE -gt 0 ]; then
PERCENTAGE=$(cat coverage/lcov.info | grep -E "SF:.+\.ts$" | xargs -I {} sh -c 'grep -A 1 "SF:{}" coverage/lcov.info | tail -1 | cut -d: -f2 | cut -d, -f1' | awk '{sum+=$1} END {print int(sum/NR)}')
else
PERCENTAGE=0
fi
# Determine color based on coverage
if [ $PERCENTAGE -ge 80 ]; then
COLOR=green
elif [ $PERCENTAGE -ge 60 ]; then
COLOR=yellow
else
COLOR=red
fi
# Create badge URL
BADGE_URL="https://img.shields.io/badge/coverage-${PERCENTAGE}%25-${COLOR}"
# Update README with new badge
sed -i "s|https://img.shields.io/badge/coverage-[0-9]*%25-[a-z]*|${BADGE_URL}|g" README.md
echo "Updated coverage badge to ${PERCENTAGE}%"
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git diff --quiet && git diff --staged --quiet || git commit -m "Update coverage badge"
git push