Skip to content

Commit 1f45ae0

Browse files
committed
refactor: 🚚 separate the moving parts a bit for modularity
1 parent 951d946 commit 1f45ae0

File tree

14 files changed

+1015
-197
lines changed

14 files changed

+1015
-197
lines changed

.github/workflows/example.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Example Coverage Workflow
22
on:
33
pull_request:
44
branches: [main]
5+
push:
6+
branches: [main]
57

68
permissions:
79
pull-requests: write
@@ -32,6 +34,13 @@ jobs:
3234
show-files: "true"
3335
coverage-threshold: "80"
3436
make-badges: "true"
35-
upload-badges-to-pages: "true"
37+
38+
# Upload badges to GitHub Pages (only on main branch)
39+
- name: Upload Badges to GitHub Pages
40+
if: github.ref == 'refs/heads/main'
41+
uses: ./
42+
with:
43+
action: "badge-upload-action.yml"
44+
badges-dir: "badges"
3645
pages-branch: "gh-pages"
3746
pages-badges-dir: "badges"

ACTION_README.md

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ A GitHub Action that automatically creates beautiful coverage reports in pull re
1010
- 🔄 **Smart Updates**: Updates existing comments instead of creating duplicates
1111
- 🎨 **Visual Indicators**: Uses emojis to quickly identify coverage status
1212
- 🏷️ **Coverage Badges**: Generates shields.io compatible badges locally
13-
- 🚀 **Automatic GitHub Pages Upload**: Uploads badges to GitHub Pages
1413
-**Lightweight**: Pure YAML and shell commands, no JavaScript complexity
1514
- 🔧 **Reliable**: No module system issues or permission headaches
1615

@@ -26,7 +25,6 @@ on:
2625

2726
permissions:
2827
pull-requests: write
29-
contents: write # Required for GitHub Pages upload
3028

3129
jobs:
3230
coverage:
@@ -49,13 +47,15 @@ jobs:
4947
uses: glideapps/vitest-v8-json-coverage-summary@v1
5048
```
5149
52-
### Advanced Usage
50+
### Advanced Usage with Badge Upload
5351
5452
```yaml
55-
name: Coverage Report
53+
name: Coverage Report with Badge Upload
5654
on:
5755
pull_request:
5856
branches: [main]
57+
push:
58+
branches: [main]
5959

6060
permissions:
6161
pull-requests: write
@@ -78,6 +78,7 @@ jobs:
7878
- name: Run tests with coverage
7979
run: npm test
8080

81+
# Coverage reporting (runs on PRs and main)
8182
- name: Report Coverage
8283
uses: glideapps/[email protected]
8384
with:
@@ -86,33 +87,47 @@ jobs:
8687
show-files: "true"
8788
coverage-threshold: "90"
8889
make-badges: "true"
89-
upload-badges-to-pages: "true"
90-
pages-branch: "gh-pages"
91-
pages-badges-dir: "badges"
9290

93-
# Optional: Upload badges to GitHub Pages
94-
- name: Deploy badges to GitHub Pages
95-
if: github.ref == 'refs/heads/main'
96-
uses: peaceiris/actions-gh-pages@v3
91+
# Badge upload (only runs on main branch)
92+
upload-badges:
93+
if: github.ref == 'refs/heads/main'
94+
runs-on: ubuntu-latest
95+
needs: coverage
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0 # Needed for git operations
100+
101+
- name: Upload Badges to GitHub Pages
102+
uses: glideapps/[email protected]
97103
with:
98-
github_token: ${{ secrets.GITHUB_TOKEN }}
99-
publish_dir: ./badges
100-
destination_dir: badges
104+
action: "badge-upload-action.yml"
105+
badges-dir: "badges"
106+
pages-branch: "gh-pages"
107+
pages-badges-dir: "badges"
101108
```
102109
103110
## Inputs
104111
105-
| Input | Description | Required | Default |
106-
| ------------------------ | --------------------------------------------------------- | -------- | -------------------------------- |
107-
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
108-
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
109-
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
110-
| `show-files` | Whether to show individual file coverage details | No | `true` |
111-
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
112-
| `make-badges` | Whether to generate coverage badges in a badges directory | No | `true` |
113-
| `upload-badges-to-pages` | Whether to automatically upload badges to GitHub Pages | No | `true` |
114-
| `pages-branch` | Branch to upload badges to for GitHub Pages | No | `gh-pages` |
115-
| `pages-badges-dir` | Directory within the pages branch to store badges | No | `badges` |
112+
| Input | Description | Required | Default |
113+
| -------------------- | --------------------------------------------------------- | -------- | -------------------------------- |
114+
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
115+
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
116+
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
117+
| `show-files` | Whether to show individual file coverage details | No | `true` |
118+
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
119+
| `make-badges` | Whether to generate coverage badges in a badges directory | No | `true` |
120+
121+
## Badge Upload Action
122+
123+
For uploading badges to GitHub Pages, use the separate `badge-upload-action.yml`:
124+
125+
| Input | Description | Required | Default |
126+
| ------------------ | ------------------------------------------------- | -------- | ---------------------------------- |
127+
| `badges-dir` | Directory containing the badges to upload | No | `badges` |
128+
| `pages-branch` | Branch to upload badges to for GitHub Pages | No | `gh-pages` |
129+
| `pages-badges-dir` | Directory within the pages branch to store badges | No | `badges` |
130+
| `commit-message` | Commit message for badge updates | No | `Update coverage badges [skip ci]` |
116131

117132
## Coverage File Format
118133

@@ -227,7 +242,7 @@ When `make-badges` is enabled (default: `true`), the action creates a `badges` d
227242

228243
### Using Badges with GitHub Pages
229244

230-
The action automatically uploads badges to your GitHub Pages branch when `upload-badges-to-pages` is enabled (default: `true`).
245+
The badge upload action automatically uploads badges to your GitHub Pages branch.
231246

232247
**Automatic Setup:**
233248

README.md

Lines changed: 151 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Vitest V8 JSON Coverage Summary
22

3-
A plugin for [Vitest](https://vitest.dev/) that generates a structured JSON coverage summary from V8 coverage data. This reporter creates a `coverage-summary.json` file with detailed coverage information for statements, branches, functions, and lines.
3+
A plugin for [Vitest](https://vitest.dev/) that generates a structured JSON coverage summary from V8 coverage data. This package also includes GitHub Actions for coverage reporting and badge management.
44

55
## Features
66

@@ -9,22 +9,63 @@ A plugin for [Vitest](https://vitest.dev/) that generates a structured JSON cove
99
- ✅ Includes file-level and overall coverage statistics
1010
- ✅ Tracks uncovered lines for detailed analysis
1111
- ✅ Compatible with Vitest 3.0+
12-
- 🚀 **NEW**: GitHub Action for automatic PR coverage reporting
13-
- 🏷️ **NEW**: Automatic coverage badge generation for GitHub Pages
14-
- 🚀 **NEW**: Automatic upload of badges to GitHub Pages
15-
- 🔧 **NEW**: Pure YAML implementation - no JavaScript complexity
12+
- 🚀 **GitHub Actions**: Coverage reporting, badge generation, and badge upload
13+
- 🏷️ **Coverage Badges**: Shields.io compatible badges
14+
- 🔧 **Modular Design**: Separate actions for different use cases
1615

1716
## Installation
1817

1918
```bash
2019
npm install --save-dev vitest-v8-json-coverage-summary
2120
```
2221

23-
## GitHub Action
22+
## GitHub Actions
2423

25-
This package also includes a GitHub Action that automatically creates beautiful coverage reports in pull requests and uploads coverage badges to GitHub Pages. Built with pure YAML and shell commands for maximum reliability.
24+
This package includes three separate GitHub Actions that can be used independently:
2625

27-
### Quick Start
26+
### 1. Coverage Reporter
27+
28+
Creates beautiful coverage reports in pull requests.
29+
30+
```yaml
31+
- name: Report Coverage
32+
uses: glideapps/vitest-v8-json-coverage-summary/actions/[email protected]
33+
with:
34+
coverage-file: "coverage/coverage-summary.json"
35+
title: "🧪 Test Coverage Report"
36+
show-files: "true"
37+
coverage-threshold: "80"
38+
```
39+
40+
### 2. Badge Generator
41+
42+
Generates coverage badges from coverage data.
43+
44+
```yaml
45+
- name: Generate Badges
46+
uses: glideapps/vitest-v8-json-coverage-summary/actions/[email protected]
47+
with:
48+
coverage-file: "coverage/coverage-summary.json"
49+
badges-dir: "badges"
50+
```
51+
52+
### 3. Badge Uploader
53+
54+
Uploads badges to GitHub Pages.
55+
56+
```yaml
57+
- name: Upload Badges to GitHub Pages
58+
uses: glideapps/vitest-v8-json-coverage-summary/actions/[email protected]
59+
with:
60+
coverage-file: "coverage/coverage-summary.json"
61+
badges-dir: "badges"
62+
pages-branch: "gh-pages"
63+
generate-badges: "true"
64+
```
65+
66+
## Quick Start
67+
68+
### Basic Coverage Reporting
2869
2970
```yaml
3071
name: Coverage Report
@@ -34,7 +75,6 @@ on:
3475

3576
permissions:
3677
pull-requests: write
37-
contents: write # Required for GitHub Pages upload
3878

3979
jobs:
4080
coverage:
@@ -46,20 +86,86 @@ jobs:
4686
node-version: "20"
4787
- run: npm ci
4888
- run: npm test
49-
- uses: glideapps/[email protected]
89+
- uses: glideapps/vitest-v8-json-coverage-summary/actions/coverage-reporter@v0.0.0-echo
5090
with:
5191
coverage-file: "coverage/coverage-summary.json"
5292
```
5393
54-
The action will automatically:
94+
### Full Workflow with Badges
5595
56-
- Create coverage reports in pull request comments
57-
- Generate coverage badges
58-
- Upload badges to the `gh-pages` branch for GitHub Pages
96+
```yaml
97+
name: Coverage with Badges
98+
on:
99+
pull_request:
100+
branches: [main]
101+
push:
102+
branches: [main]
59103

60-
**Built with pure YAML and shell commands** - no JavaScript complexity, no module system issues, no permission headaches!
104+
permissions:
105+
pull-requests: write
106+
contents: write
61107

62-
### Badge URLs
108+
jobs:
109+
coverage:
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: actions/checkout@v4
113+
- uses: actions/setup-node@v4
114+
with:
115+
node-version: "20"
116+
- run: npm ci
117+
- run: npm test
118+
- uses: glideapps/vitest-v8-json-coverage-summary/actions/[email protected]
119+
120+
badges:
121+
if: github.ref == 'refs/heads/main'
122+
runs-on: ubuntu-latest
123+
needs: coverage
124+
steps:
125+
- uses: actions/checkout@v4
126+
with:
127+
fetch-depth: 0
128+
- uses: actions/setup-node@v4
129+
with:
130+
node-version: "20"
131+
- run: npm ci
132+
- run: npm test
133+
- uses: glideapps/vitest-v8-json-coverage-summary/actions/[email protected]
134+
with:
135+
generate-badges: "true"
136+
```
137+
138+
## Action Reference
139+
140+
### Coverage Reporter
141+
142+
| Input | Description | Required | Default |
143+
| -------------------- | ------------------------------------------------------- | -------- | -------------------------------- |
144+
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
145+
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
146+
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
147+
| `show-files` | Whether to show individual file coverage details | No | `true` |
148+
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
149+
150+
### Badge Generator
151+
152+
| Input | Description | Required | Default |
153+
| --------------- | ---------------------------------------- | -------- | -------------------------------- |
154+
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
155+
| `badges-dir` | Directory to output the generated badges | No | `badges` |
156+
157+
### Badge Uploader
158+
159+
| Input | Description | Required | Default |
160+
| ------------------ | ------------------------------------------------- | -------- | ---------------------------------- |
161+
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
162+
| `badges-dir` | Directory containing the badges to upload | No | `badges` |
163+
| `pages-branch` | Branch to upload badges to for GitHub Pages | No | `gh-pages` |
164+
| `pages-badges-dir` | Directory within the pages branch to store badges | No | `badges` |
165+
| `commit-message` | Commit message for badge updates | No | `Update coverage badges [skip ci]` |
166+
| `generate-badges` | Whether to generate badges if they don't exist | No | `true` |
167+
168+
## Badge URLs
63169

64170
When GitHub Pages is enabled, badges are available at:
65171

@@ -77,35 +183,45 @@ Use in your README.md:
77183
![Coverage](https://yourusername.github.io/yourrepo/badges/coverage.json)
78184
```
79185

80-
For detailed documentation, see [ACTION_README.md](ACTION_README.md).
186+
## Examples
81187

82-
## Usage
188+
See the `examples/` directory for complete workflow examples:
83189

84-
### Basic Setup
190+
- `coverage-only.yml` - Only coverage reporting
191+
- `badge-generator-only.yml` - Only badge generation
192+
- `badge-uploader-only.yml` - Only badge upload
193+
- `full-workflow.yml` - Complete workflow with all actions
85194

86-
Add the reporter to your Vitest configuration:
195+
## Setup
196+
197+
### Configure Vitest
87198

88199
```javascript
89200
// vitest.config.js
90-
import { defineConfig } from "vitest/config";
91-
import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
92-
93-
export default defineConfig({
94-
test: {
95-
coverage: {
96-
provider: "v8",
97-
reporter: ["text", "json"],
98-
reportsDirectory: "./coverage",
99-
},
100-
reporters: ["default", new V8JSONSummaryReporter()],
201+
export default {
202+
coverage: {
203+
provider: "v8",
204+
reporter: ["json-summary"],
205+
reportsDirectory: "coverage",
101206
},
102-
});
207+
};
103208
```
104209

105-
### TypeScript Configuration
210+
### Enable GitHub Pages
211+
212+
1. Go to Settings → Pages
213+
2. Set source to "Deploy from a branch"
214+
3. Select `gh-pages` branch
215+
4. Set folder to `/ (root)` or `/badges`
216+
217+
## Usage
218+
219+
### Basic Setup
220+
221+
Add the reporter to your Vitest configuration:
106222

107-
```typescript
108-
// vitest.config.ts
223+
```javascript
224+
// vitest.config.js
109225
import { defineConfig } from "vitest/config";
110226
import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
111227

0 commit comments

Comments
 (0)