Skip to content

Commit 42c920e

Browse files
authored
feat: self-host star history chart to fix broken embed
GitHub restricted detailed stargazer history to repo admins/collaborators, which broke star-history.com's unauthenticated README embed. - Add scripts/generate-star-history: Python script that fetches star data from GitHub API and renders a self-contained SVG chart - Add .github/workflows/star-history.yml: weekly CI job that regenerates the chart using the workflow's GITHUB_TOKEN and commits the updated SVG - Add docs/images/star-history.svg: initial chart generated from seed data - Update docs/README.md: replace broken api.star-history.com embed with a reference to the self-hosted SVG Closes #2040
1 parent ab34833 commit 42c920e

4 files changed

Lines changed: 629 additions & 1 deletion

File tree

.github/workflows/star-history.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Star history chart
2+
3+
## Regenerates the README's star-history chart. GitHub restricted
4+
## detailed stargazer history to repo admins/collaborators, which broke
5+
## star-history.com's unauthenticated embed — so we render the chart
6+
## ourselves with the repo-scoped workflow token and commit the SVG.
7+
on:
8+
workflow_dispatch:
9+
schedule:
10+
## Weekly, Monday 06:20 UTC — off the top of the hour to dodge the
11+
## scheduled-workflow load spike.
12+
- cron: "20 6 * * 1"
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
update-chart:
19+
runs-on: ubuntu-latest
20+
## Scheduled runs on forks would fail (no stargazer access) and spam.
21+
if: github.repository == 'commitizen-tools/commitizen'
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.12"
29+
30+
- name: Generate chart
31+
env:
32+
GITHUB_TOKEN: ${{ github.token }}
33+
## Optional fallback: a collaborator PAT, only needed if GitHub
34+
## ever stops granting the workflow token stargazer access.
35+
STAR_HISTORY_TOKEN: ${{ secrets.STAR_HISTORY_TOKEN }}
36+
run: python scripts/generate-star-history --repo "$GITHUB_REPOSITORY"
37+
38+
- name: Commit updated chart
39+
run: |
40+
## Stage first so a brand-new (untracked) chart is detected too —
41+
## `git diff --quiet` alone ignores untracked files.
42+
git add docs/images/star-history.svg docs/images/star-history.json
43+
if git diff --staged --quiet; then
44+
echo "chart unchanged, nothing to commit"
45+
exit 0
46+
fi
47+
git config user.name "github-actions[bot]"
48+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49+
git commit -m "chore: update star history chart [skip ci]"
50+
git push

docs/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@ For more detailed information about argcomplete configuration and troubleshootin
305305
306306
## Star History
307307
308-
[![Star History Chart](https://api.star-history.com/svg?repos=commitizen-tools/commitizen)](https://star-history.com/#commitizen-tools/commitizen)
308+
<!-- Regenerated weekly by .github/workflows/star-history.yml:
309+
GitHub restricted stargazer history to repo collaborators, which broke
310+
star-history.com's unauthenticated embed, so the chart is now rendered
311+
in CI and committed here. -->
312+
<a href="https://github.com/commitizen-tools/commitizen/stargazers">
313+
<img src="images/star-history.svg" alt="Star History Chart" width="700">
314+
</a>
309315
310316
311317
## Sponsors

docs/images/star-history.svg

Lines changed: 36 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)