diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index 8686d57..6d48bf4 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -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 ./... diff --git a/README.md b/README.md index 69fc910..4f5f4e9 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/arcodange/DanceLessonsCoach)](https://goreportcard.com/report/github.com/arcodange/DanceLessonsCoach) [![Version](https://img.shields.io/badge/version-1.4.0-blue.svg)](https://gitea.arcodange.fr/arcodange/DanceLessonsCoach/releases) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) +[![Coverage](https://img.shields.io/badge/coverage-0%-red?style=flat-square)](https://gitea.arcodange.lab/arcodange/dance-lessons-coach) A Go project demonstrating idiomatic package structure, CLI implementation, and JSON API with Chi router. =======