Skip to content

Commit 9cfffb0

Browse files
committed
feat: ✨ try the gh pages upload again now that we aren't self harming with JS
1 parent e2888d9 commit 9cfffb0

File tree

4 files changed

+150
-28
lines changed

4 files changed

+150
-28
lines changed

.github/workflows/example.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Example Coverage Workflow
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
permissions:
7+
pull-requests: write
8+
contents: write # Required for GitHub Pages upload
9+
10+
jobs:
11+
coverage:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "20"
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Run tests with coverage
25+
run: npm test
26+
27+
- name: Report Coverage
28+
uses: ./
29+
with:
30+
coverage-file: "coverage/coverage-summary.json"
31+
title: "🧪 Test Coverage Report"
32+
show-files: "true"
33+
coverage-threshold: "80"
34+
make-badges: "true"
35+
upload-badges-to-pages: "true"
36+
pages-branch: "gh-pages"
37+
pages-badges-dir: "badges"

ACTION_README.md

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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
1314
-**Lightweight**: Pure YAML and shell commands, no JavaScript complexity
1415
- 🔧 **Reliable**: No module system issues or permission headaches
1516

@@ -58,6 +59,7 @@ on:
5859

5960
permissions:
6061
pull-requests: write
62+
contents: write # Required for GitHub Pages upload
6163

6264
jobs:
6365
coverage:
@@ -84,6 +86,9 @@ jobs:
8486
show-files: "true"
8587
coverage-threshold: "90"
8688
make-badges: "true"
89+
upload-badges-to-pages: "true"
90+
pages-branch: "gh-pages"
91+
pages-badges-dir: "badges"
8792

8893
# Optional: Upload badges to GitHub Pages
8994
- name: Deploy badges to GitHub Pages
@@ -97,14 +102,17 @@ jobs:
97102
98103
## Inputs
99104
100-
| Input | Description | Required | Default |
101-
| -------------------- | --------------------------------------------------------- | -------- | -------------------------------- |
102-
| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
103-
| `token` | GitHub token for creating comments | No | `${{ github.token }}` |
104-
| `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
105-
| `show-files` | Whether to show individual file coverage details | No | `true` |
106-
| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
107-
| `make-badges` | Whether to generate coverage badges in a badges directory | No | `true` |
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` |
108116

109117
## Coverage File Format
110118

@@ -219,27 +227,37 @@ When `make-badges` is enabled (default: `true`), the action creates a `badges` d
219227

220228
### Using Badges with GitHub Pages
221229

222-
The action generates badges locally. To deploy them to GitHub Pages, use a separate action:
230+
The action automatically uploads badges to your GitHub Pages branch when `upload-badges-to-pages` is enabled (default: `true`).
223231

224-
```yaml
225-
- name: Deploy badges to GitHub Pages
226-
if: github.ref == 'refs/heads/main'
227-
uses: peaceiris/actions-gh-pages@v3
228-
with:
229-
github_token: ${{ secrets.GITHUB_TOKEN }}
230-
publish_dir: ./badges
231-
destination_dir: badges
232+
**Automatic Setup:**
233+
234+
- Creates the `gh-pages` branch if it doesn't exist
235+
- Uploads badges to the specified directory
236+
- Commits and pushes changes automatically
237+
238+
**Enable GitHub Pages** in your repository settings:
239+
240+
1. Go to Settings → Pages
241+
2. Set source to "Deploy from a branch"
242+
3. Select your `gh-pages` branch (or the branch specified in `pages-branch`)
243+
4. Set folder to `/ (root)` or `/badges` depending on your preference
244+
245+
**Badge URLs** will be available at:
246+
247+
```
248+
https://yourusername.github.io/yourrepo/badges/coverage.json
249+
https://yourusername.github.io/yourrepo/badges/statements.json
250+
https://yourusername.github.io/yourrepo/badges/branches.json
251+
https://yourusername.github.io/yourrepo/badges/functions.json
252+
https://yourusername.github.io/yourrepo/badges/lines.json
232253
```
233254

234-
### Example Badge JSON
255+
**Use in your README.md:**
235256

236-
```json
237-
{
238-
"schemaVersion": 1,
239-
"label": "coverage",
240-
"message": "89.8%",
241-
"color": "green"
242-
}
257+
```markdown
258+
![Coverage](https://yourusername.github.io/yourrepo/badges/coverage.json)
259+
![Statements](https://yourusername.github.io/yourrepo/badges/statements.json)
260+
![Branches](https://yourusername.github.io/yourrepo/badges/branches.json)
243261
```
244262

245263
### Required Permissions

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434

3535
permissions:
3636
pull-requests: write
37+
contents: write # Required for GitHub Pages upload
3738

3839
jobs:
3940
coverage:
@@ -45,10 +46,9 @@ jobs:
4546
node-version: "20"
4647
- run: npm ci
4748
- run: npm test
48-
- uses: glideapps/vitest-v8-json-coverage-summary@v1
49+
- uses: glideapps/vitest-v8-json-coverage-summary@v0.0.0-echo
4950
with:
50-
make-badges: "true"
51-
upload-badges-to-pages: "true"
51+
coverage-file: "coverage/coverage-summary.json"
5252
```
5353
5454
The action will automatically:
@@ -59,6 +59,24 @@ The action will automatically:
5959

6060
**Built with pure YAML and shell commands** - no JavaScript complexity, no module system issues, no permission headaches!
6161

62+
### Badge URLs
63+
64+
When GitHub Pages is enabled, badges are available at:
65+
66+
```
67+
https://yourusername.github.io/yourrepo/badges/coverage.json
68+
https://yourusername.github.io/yourrepo/badges/statements.json
69+
https://yourusername.github.io/yourrepo/badges/branches.json
70+
https://yourusername.github.io/yourrepo/badges/functions.json
71+
https://yourusername.github.io/yourrepo/badges/lines.json
72+
```
73+
74+
Use in your README.md:
75+
76+
```markdown
77+
![Coverage](https://yourusername.github.io/yourrepo/badges/coverage.json)
78+
```
79+
6280
For detailed documentation, see [ACTION_README.md](ACTION_README.md).
6381

6482
## Usage

action.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ inputs:
3030
description: "Whether to generate coverage badges in a badges directory"
3131
required: false
3232
default: "true"
33+
upload-badges-to-pages:
34+
description: "Whether to automatically upload badges to GitHub Pages branch"
35+
required: false
36+
default: "true"
37+
pages-branch:
38+
description: "Branch to upload badges to for GitHub Pages"
39+
required: false
40+
default: "gh-pages"
41+
pages-badges-dir:
42+
description: "Directory within the pages branch to store badges"
43+
required: false
44+
default: "badges"
3345

3446
runs:
3547
using: "composite"
@@ -101,6 +113,43 @@ runs:
101113
echo " - functions.json: $FUNCTIONS% ($FUNCTIONS_COLOR)"
102114
echo " - lines.json: $LINES% ($LINES_COLOR)"
103115
116+
- name: Upload badges to GitHub Pages
117+
if: inputs.make-badges == 'true' && inputs.upload-badges-to-pages == 'true'
118+
shell: bash
119+
run: |
120+
# Configure git
121+
git config --local user.email "[email protected]"
122+
git config --local user.name "GitHub Action"
123+
124+
# Create or checkout the pages branch
125+
if git show-ref --verify --quiet refs/remotes/origin/${{ inputs.pages-branch }}; then
126+
echo "📁 Checking out existing ${{ inputs.pages-branch }} branch"
127+
git checkout ${{ inputs.pages-branch }}
128+
git pull origin ${{ inputs.pages-branch }}
129+
else
130+
echo "🆕 Creating new ${{ inputs.pages-branch }} branch from current branch"
131+
git checkout --orphan ${{ inputs.pages-branch }}
132+
git rm -rf . || true
133+
fi
134+
135+
# Create the badges directory
136+
mkdir -p ${{ inputs.pages-badges-dir }}
137+
138+
# Copy badges to the pages branch
139+
cp badges/*.json ${{ inputs.pages-badges-dir }}/
140+
echo "📋 Copied badges to ${{ inputs.pages-badges-dir }}/"
141+
142+
# Check if there are changes to commit
143+
if git diff --quiet && git diff --cached --quiet; then
144+
echo "ℹ️ No changes to commit"
145+
else
146+
# Commit and push changes
147+
git add ${{ inputs.pages-badges-dir }}/
148+
git commit -m "Update coverage badges [skip ci]"
149+
git push origin ${{ inputs.pages-branch }}
150+
echo "✅ Successfully uploaded badges to ${{ inputs.pages-branch }} branch"
151+
fi
152+
104153
- name: Generate coverage report
105154
shell: bash
106155
run: |

0 commit comments

Comments
 (0)