Skip to content

Commit 2f557bb

Browse files
SoulKyuclaude
andcommitted
ci: add coverage badge with auto-update on main
- Generate SVG coverage badge in CI after tests (cross-package coverage) - Badge committed automatically on push to main via github-actions bot - Initial badge: 67.0% (yellow, green threshold at 70%) - Badge displayed in README next to CI status badge Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7a8bcff commit 2f557bb

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

.github/badges/coverage.svg

Lines changed: 18 additions & 0 deletions
Loading

.github/workflows/ci.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,46 @@ jobs:
2222
go-version-file: go.mod
2323
cache: true
2424

25-
- name: Run unit tests
26-
run: go test ./internal/... -count=1 -timeout 5m
25+
- name: Run unit tests with coverage
26+
run: go test -coverpkg=github.com/numberly/opentofu-provider-flashblade/internal/... -coverprofile=coverage.out ./internal/... -count=1 -timeout 5m
27+
28+
- name: Generate coverage badge
29+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
30+
run: |
31+
PCT=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
32+
# Color: red < 50, yellow < 70, green >= 70
33+
if (( $(echo "$PCT < 50" | bc -l) )); then COLOR="e05d44"
34+
elif (( $(echo "$PCT < 70" | bc -l) )); then COLOR="dfb317"
35+
else COLOR="44cc11"; fi
36+
mkdir -p .github/badges
37+
cat > .github/badges/coverage.svg << BADGE
38+
<svg xmlns="http://www.w3.org/2000/svg" width="106" height="20">
39+
<linearGradient id="b" x2="0" y2="100%">
40+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
41+
<stop offset="1" stop-opacity=".1"/>
42+
</linearGradient>
43+
<mask id="a"><rect width="106" height="20" rx="3" fill="#fff"/></mask>
44+
<g mask="url(#a)">
45+
<path fill="#555" d="M0 0h61v20H0z"/>
46+
<path fill="#${COLOR}" d="M61 0h45v20H61z"/>
47+
<path fill="url(#b)" d="M0 0h106v20H0z"/>
48+
</g>
49+
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11">
50+
<text x="30.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
51+
<text x="30.5" y="14">coverage</text>
52+
<text x="83" y="15" fill="#010101" fill-opacity=".3">${PCT}%</text>
53+
<text x="83" y="14">${PCT}%</text>
54+
</g>
55+
</svg>
56+
BADGE
57+
58+
- name: Commit coverage badge
59+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
60+
run: |
61+
git config user.name "github-actions[bot]"
62+
git config user.email "github-actions[bot]@users.noreply.github.com"
63+
git add .github/badges/coverage.svg
64+
git diff --cached --quiet || git commit -m "ci: update coverage badge [skip ci]" && git push
2765
2866
lint:
2967
name: Lint

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Terraform Provider FlashBlade
22

33
[![CI](https://github.com/numberly/opentofu-provider-flashblade/actions/workflows/ci.yml/badge.svg)](https://github.com/numberly/opentofu-provider-flashblade/actions/workflows/ci.yml)
4+
![Coverage](https://raw.githubusercontent.com/numberly/opentofu-provider-flashblade/main/.github/badges/coverage.svg)
45

56
Terraform provider for [Pure Storage FlashBlade](https://www.purestorage.com/products/file-and-object/flashblade.html), managing storage resources via the FlashBlade REST API v2.22.
67

0 commit comments

Comments
 (0)