@@ -67,16 +67,28 @@ jobs:
6767 ${{ runner.os }}-cargo-test-
6868
6969 - name : Run tests with coverage
70- run : cargo llvm-cov --workspace --json --output-path coverage.json --summary-only
70+ run : cargo llvm-cov --workspace --json --output-path coverage.json
7171
72- - name : Convert coverage to json-summary format
72+ - name : Generate coverage badge
73+ if : github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
7374 run : |
74- COVERAGE=$(cat coverage.json | jq '.data[0].totals.lines.percent')
75- echo "{\"total\":{\"lines\":{\"pct\":$COVERAGE}}}" > coverage-summary.json
76-
77- - name : Update Coverage Badge
75+ COVERAGE=$(jq '.data[0].totals.lines.percent // 0' coverage.json)
76+ echo "Coverage: $COVERAGE%"
77+ mkdir -p badges
78+ if (( $(echo "$COVERAGE >= 80" | bc -l) )); then COLOR="brightgreen"
79+ elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then COLOR="green"
80+ elif (( $(echo "$COVERAGE >= 40" | bc -l) )); then COLOR="yellow"
81+ else COLOR="red"; fi
82+ curl -s "https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR}" > badges/coverage.svg
83+
84+ - name : Deploy coverage badge
7885 if : github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
79- uses : we-cli/coverage-badge-action@main
86+ uses : peaceiris/actions-gh-pages@v4
87+ with :
88+ github_token : ${{ secrets.GITHUB_TOKEN }}
89+ publish_dir : ./badges
90+ destination_dir : badges
91+ keep_files : true
8092
8193 clippy :
8294 name : Clippy
0 commit comments