Skip to content

Commit 7d677dc

Browse files
authored
Merge pull request #6 from Avicted/verifying
Badge test, CI deduplication fix
2 parents dc69e55 + f3fa0ca commit 7d677dc

File tree

2 files changed

+66
-46
lines changed

2 files changed

+66
-46
lines changed

.github/workflows/badge.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: badge
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
coverage:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: "1.22"
24+
cache: true
25+
26+
- name: Generate coverage
27+
run: ./scripts/coverage.sh | tee coverage-report.txt
28+
29+
- name: Generate coverage badge
30+
run: |
31+
total=$(go tool cover -func=coverage.out | awk '/^total:/ { sub(/%/,"",$3); print $3 }')
32+
if [[ -z "$total" ]]; then
33+
echo "coverage total not found" >&2
34+
exit 1
35+
fi
36+
color="red"
37+
if awk "BEGIN {exit !($total >= 80)}"; then
38+
color="brightgreen"
39+
elif awk "BEGIN {exit !($total >= 60)}"; then
40+
color="yellow"
41+
fi
42+
mkdir -p public/badges
43+
cat > public/badges/coverage.svg <<EOF
44+
<svg xmlns="http://www.w3.org/2000/svg" width="130" height="20" role="img" aria-label="coverage: ${total}%">
45+
<linearGradient id="s" x2="0" y2="100%">
46+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
47+
<stop offset="1" stop-opacity=".1"/>
48+
</linearGradient>
49+
<rect rx="3" width="130" height="20" fill="#555"/>
50+
<rect rx="3" x="62" width="68" height="20" fill="${color}"/>
51+
<path fill="${color}" d="M62 0h4v20h-4z"/>
52+
<rect rx="3" width="130" height="20" fill="url(#s)"/>
53+
<g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">
54+
<text x="31" y="14">coverage</text>
55+
<text x="96" y="14">${total}%</text>
56+
</g>
57+
</svg>
58+
EOF
59+
60+
- name: Publish coverage badge
61+
uses: peaceiris/actions-gh-pages@v4
62+
with:
63+
github_token: ${{ secrets.GITHUB_TOKEN }}
64+
publish_dir: public
65+
keep_files: true

.github/workflows/ci.yml

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ on:
44
pull_request:
55
branches:
66
- "**"
7-
push:
8-
branches:
9-
- "main"
10-
- "master"
11-
workflow_dispatch:
127

138
permissions:
14-
contents: write
9+
contents: read
1510

1611
jobs:
1712
test:
@@ -39,46 +34,6 @@ jobs:
3934
- name: Coverage
4035
run: ./scripts/coverage.sh | tee coverage-report.txt
4136

42-
- name: Generate coverage badge
43-
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
44-
run: |
45-
total=$(go tool cover -func=coverage.out | awk '/^total:/ { sub(/%/,"",$3); print $3 }')
46-
if [[ -z "$total" ]]; then
47-
echo "coverage total not found" >&2
48-
exit 1
49-
fi
50-
color="red"
51-
if awk "BEGIN {exit !($total >= 80)}"; then
52-
color="brightgreen"
53-
elif awk "BEGIN {exit !($total >= 60)}"; then
54-
color="yellow"
55-
fi
56-
mkdir -p public/badges
57-
cat > public/badges/coverage.svg <<EOF
58-
<svg xmlns="http://www.w3.org/2000/svg" width="130" height="20" role="img" aria-label="coverage: ${total}%">
59-
<linearGradient id="s" x2="0" y2="100%">
60-
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
61-
<stop offset="1" stop-opacity=".1"/>
62-
</linearGradient>
63-
<rect rx="3" width="130" height="20" fill="#555"/>
64-
<rect rx="3" x="62" width="68" height="20" fill="${color}"/>
65-
<path fill="${color}" d="M62 0h4v20h-4z"/>
66-
<rect rx="3" width="130" height="20" fill="url(#s)"/>
67-
<g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">
68-
<text x="31" y="14">coverage</text>
69-
<text x="96" y="14">${total}%</text>
70-
</g>
71-
</svg>
72-
EOF
73-
74-
- name: Publish coverage badge
75-
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
76-
uses: peaceiris/actions-gh-pages@v4
77-
with:
78-
github_token: ${{ secrets.GITHUB_TOKEN }}
79-
publish_dir: public
80-
keep_files: true
81-
8237
- name: Upload coverage profile
8338
uses: actions/upload-artifact@v4
8439
with:

0 commit comments

Comments
 (0)