Skip to content

Commit aaca482

Browse files
committed
Replace Coveralls badge with self-hosted coverage badge on GitHub Pages
Mirrors the active_admin_sidebar setup. SimpleCov already runs in the coverage job; this commit adds: - A step that reads coverage/.last_run.json, picks a shields.io color bucket, and writes a static badge.json in the shields endpoint format - An upload-artifact step for the badge - A deploy-coverage job (master pushes only) that downloads the badge and deploys it to GitHub Pages via actions/deploy-pages@v4 - Top-level permissions block (contents/pages/id-token) required by the Pages deployment actions The README badge is switched from the dead Coveralls endpoint (no workflow has pushed to it for years) to a shields.io endpoint badge pointing at the new gh-pages-served badge.json. After merging, the Pages source needs to be flipped from the legacy gh-pages branch to "GitHub Actions" workflow build, after which the gh-pages branch can be deleted.
1 parent 688e5e1 commit aaca482

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

.github/workflows/test.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ on:
33
pull_request:
44
push:
55
branches: [master]
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
612
jobs:
713
test:
814
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} / SQLite
@@ -108,3 +114,49 @@ jobs:
108114
with:
109115
name: coverage
110116
path: coverage/
117+
118+
- name: Generate badge.json
119+
run: |
120+
LAST_RUN="coverage/.last_run.json"
121+
if [ ! -f "$LAST_RUN" ]; then
122+
mkdir -p badge
123+
echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json
124+
exit 0
125+
fi
126+
PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)")
127+
PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')")
128+
if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen"
129+
elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green"
130+
elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow"
131+
else COLOR="red"; fi
132+
mkdir -p badge
133+
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json
134+
135+
- name: Upload badge artifact
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: coverage-badge
139+
path: badge
140+
141+
deploy-coverage:
142+
needs: coverage
143+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
144+
runs-on: ubuntu-latest
145+
environment:
146+
name: github-pages
147+
url: ${{ steps.deployment.outputs.page_url }}
148+
steps:
149+
- name: Download coverage badge
150+
uses: actions/download-artifact@v4
151+
with:
152+
name: coverage-badge
153+
path: .
154+
- name: Setup Pages
155+
uses: actions/configure-pages@v5
156+
- name: Upload Pages artifact
157+
uses: actions/upload-pages-artifact@v3
158+
with:
159+
path: .
160+
- name: Deploy to GitHub Pages
161+
id: deployment
162+
uses: actions/deploy-pages@v4

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# ActiveAdminImport
22

3-
[![Build Status ][build_badge]][build_link]
4-
[![Coverage Status][coveralls_badge]][coveralls_link]
5-
[![Code Climate ][codeclimate_badge]][codeclimate_link]
6-
[![Gem Version ][rubygems_badge]][rubygems_link]
7-
[![License ][license_badge]][license_link]
3+
[![Build Status][build_badge]][build_link]
4+
![Coverage][coverage_badge]
5+
[![Code Climate][codeclimate_badge]][codeclimate_link]
6+
[![Gem Version][rubygems_badge]][rubygems_link]
7+
[![License][license_badge]][license_link]
88

99

1010
The fastest and most efficient CSV import for Active Admin with support for validations, bulk inserts, and encoding handling.
@@ -331,8 +331,7 @@ Tool | Description
331331

332332
[build_badge]: https://github.com/activeadmin-plugins/active_admin_import/actions/workflows/test.yml/badge.svg
333333
[build_link]: https://github.com/activeadmin-plugins/active_admin_import/actions
334-
[coveralls_badge]: https://coveralls.io/repos/activeadmin-plugins/active_admin_import/badge.svg
335-
[coveralls_link]: https://coveralls.io/github/activeadmin-plugins/active_admin_import
334+
[coverage_badge]: https://img.shields.io/endpoint?url=https://activeadmin-plugins.github.io/active_admin_import/badge.json
336335
[codeclimate_badge]: https://codeclimate.com/github/activeadmin-plugins/active_admin_import/badges/gpa.svg
337336
[codeclimate_link]: https://codeclimate.com/github/activeadmin-plugins/active_admin_import
338337
[rubygems_badge]: https://badge.fury.io/rb/active_admin_import.svg

0 commit comments

Comments
 (0)