Skip to content

Commit 2a0887f

Browse files
committed
feat: ✨ basic badges starting point
1 parent 1da6055 commit 2a0887f

File tree

12 files changed

+486
-104
lines changed

12 files changed

+486
-104
lines changed

ACTION_README.md

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A GitHub Action that automatically creates beautiful coverage reports in pull re
99
- 📁 **File-level Details**: Option to show individual file coverage breakdowns
1010
- 🔄 **Smart Updates**: Updates existing comments instead of creating duplicates
1111
- 🎨 **Visual Indicators**: Uses emojis to quickly identify coverage status
12+
- 🏷️ **Coverage Badges**: Generates shields.io compatible badges for GitHub Pages
1213
-**Lightweight**: Fast execution with minimal dependencies
1314

1415
## Usage
@@ -80,17 +81,19 @@ jobs:
8081
title: "🧪 Test Coverage Report"
8182
show-files: "true"
8283
coverage-threshold: "90"
84+
make-badges: "true"
8385
```
8486
8587
## Inputs
8688
87-
| Input | Description | Required | Default |
88-
| -------------------- | ------------------------------------------------------- | -------- | -------------------------------- |
89-
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
90-
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
91-
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
92-
| `show-files` | Whether to show individual file coverage details | No | `true` |
93-
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
89+
| Input | Description | Required | Default |
90+
| -------------------- | --------------------------------------------------------- | -------- | -------------------------------- |
91+
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
92+
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
93+
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
94+
| `show-files` | Whether to show individual file coverage details | No | `true` |
95+
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
96+
| `make-badges` | Whether to generate coverage badges in a badges directory | No | `true` |
9497

9598
## Coverage File Format
9699

@@ -182,3 +185,49 @@ Contributions are welcome! Please feel free to submit a Pull Request.
182185
## License
183186

184187
MIT License - see the [LICENSE](LICENSE) file for details.
188+
189+
## Coverage Badges
190+
191+
When `make-badges` is enabled (default: `true`), the action creates a `badges` directory with shields.io compatible JSON files:
192+
193+
### Generated Badges
194+
195+
- `badges/coverage.json` - Overall coverage percentage
196+
- `badges/statements.json` - Statement coverage
197+
- `badges/branches.json` - Branch coverage
198+
- `badges/functions.json` - Function coverage
199+
- `badges/lines.json` - Line coverage
200+
201+
### Badge Colors
202+
203+
- 🟢 **Bright Green**: 90% or higher
204+
- 🟢 **Green**: 80-89%
205+
- 🟡 **Yellow**: 70-79%
206+
- 🟠 **Orange**: 60-69%
207+
- 🔴 **Red**: Below 60%
208+
209+
### Using Badges with GitHub Pages
210+
211+
1. Enable GitHub Pages in your repository settings
212+
2. Set the source to "Deploy from a branch" and select your main branch
213+
3. The badges will be available at:
214+
215+
```
216+
https://yourusername.github.io/yourrepo/badges/coverage.json
217+
```
218+
219+
4. Use in your README.md:
220+
```markdown
221+
![Coverage](https://yourusername.github.io/yourrepo/badges/coverage.json)
222+
```
223+
224+
### Example Badge JSON
225+
226+
```json
227+
{
228+
"schemaVersion": 1,
229+
"label": "coverage",
230+
"message": "89.8%",
231+
"color": "green"
232+
}
233+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A plugin for [Vitest](https://vitest.dev/) that generates a structured JSON cove
1010
- ✅ Tracks uncovered lines for detailed analysis
1111
- ✅ Compatible with Vitest 3.0+
1212
- 🚀 **NEW**: GitHub Action for automatic PR coverage reporting
13+
- 🏷️ **NEW**: Automatic coverage badge generation for GitHub Pages
1314

1415
## Installation
1516

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
description: "Minimum coverage percentage to consider as good (0-100)"
2727
required: false
2828
default: "80"
29+
make-badges:
30+
description: "Whether to generate coverage badges in a badges directory"
31+
required: false
32+
default: "true"
2933

3034
runs:
3135
using: "node20"

badges/branches.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"schemaVersion": 1,
3+
"label": "branches",
4+
"message": "95.7%",
5+
"color": "brightgreen"
6+
}

badges/coverage.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"schemaVersion": 1,
3+
"label": "coverage",
4+
"message": "84.6%",
5+
"color": "green"
6+
}

badges/functions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"schemaVersion": 1,
3+
"label": "functions",
4+
"message": "62.5%",
5+
"color": "orange"
6+
}

badges/lines.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"schemaVersion": 1,
3+
"label": "lines",
4+
"message": "90.2%",
5+
"color": "brightgreen"
6+
}

badges/statements.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"schemaVersion": 1,
3+
"label": "statements",
4+
"message": "90.2%",
5+
"color": "brightgreen"
6+
}

example-workflow-with-badges.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Coverage Report with Badges
2+
3+
on:
4+
pull_request:
5+
branches: [main, develop]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
test-and-coverage:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "20"
22+
cache: "npm"
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Run tests with coverage
28+
run: npm test
29+
30+
- name: Report Coverage
31+
uses: glideapps/vitest-v8-json-coverage-summary@v1
32+
with:
33+
coverage-file: "coverage/coverage-summary.json"
34+
title: "🧪 Test Coverage Report"
35+
show-files: "true"
36+
coverage-threshold: "80"
37+
make-badges: "true"
38+
39+
- name: Commit badges (if on main branch)
40+
if: github.ref == 'refs/heads/main'
41+
run: |
42+
git config --local user.email "[email protected]"
43+
git config --local user.name "GitHub Action"
44+
git add badges/
45+
git diff --quiet && git diff --staged --quiet || git commit -m "Update coverage badges"
46+
git push
47+
48+
# Optional: Deploy badges to GitHub Pages
49+
deploy-badges:
50+
if: github.ref == 'refs/heads/main'
51+
needs: test-and-coverage
52+
runs-on: ubuntu-latest
53+
permissions:
54+
contents: write
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Deploy to GitHub Pages
60+
uses: peaceiris/actions-gh-pages@v3
61+
with:
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
publish_dir: ./badges
64+
destination_dir: badges

example-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ jobs:
3434
title: "🧪 Test Coverage Report"
3535
show-files: "true"
3636
coverage-threshold: "80"
37+
make-badges: "true"

0 commit comments

Comments
 (0)