|
22 | 22 | go-version-file: go.mod |
23 | 23 | cache: true |
24 | 24 |
|
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 |
27 | 65 |
|
28 | 66 | lint: |
29 | 67 | name: Lint |
|
0 commit comments