📊 feat: add Shields.io coverage badge with auto-update CI
Some checks failed
CI/CD Pipeline / CI Pipeline (pull_request) Failing after 5m35s
Some checks failed
CI/CD Pipeline / CI Pipeline (pull_request) Failing after 5m35s
This commit is contained in:
@@ -79,7 +79,34 @@ jobs:
|
||||
run: go build ./...
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: go test ./... -cover -v
|
||||
run: |
|
||||
# Run tests with coverage
|
||||
go test ./... -coverprofile=coverage.out -v
|
||||
go tool cover -func=coverage.out > coverage.txt
|
||||
|
||||
# Extract coverage percentage
|
||||
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||
echo "Coverage: ${COVERAGE}%"
|
||||
|
||||
# Determine badge color
|
||||
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
|
||||
COLOR="brightgreen"
|
||||
elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then
|
||||
COLOR="yellow"
|
||||
else
|
||||
COLOR="red"
|
||||
fi
|
||||
|
||||
# Update README with new badge
|
||||
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square"
|
||||
sed -i "s|https://img.shields.io/badge/coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md
|
||||
|
||||
# Commit and push the update
|
||||
git config --global user.name "CI Bot"
|
||||
git config --global user.email "ci@arcodange.fr"
|
||||
git add README.md
|
||||
git commit -m "🤖 chore: update coverage badge to ${COVERAGE}%" || echo "No coverage change to commit"
|
||||
git push || echo "Push failed - may be duplicate commit"
|
||||
|
||||
- name: Run go fmt
|
||||
run: go fmt ./...
|
||||
|
||||
Reference in New Issue
Block a user