| 1 | name: Star History |
| 2 | |
| 3 | on: |
| 4 | schedule: |
| 5 | # 每天一次。星标曲线一周才动一次的话,图上那一段是平的—— |
| 6 | # 而它存在的意义正是让人看见增长的形状 |
| 7 | - cron: "0 0 * * *" |
| 8 | workflow_dispatch: |
| 9 | |
| 10 | permissions: |
| 11 | contents: write |
| 12 | |
| 13 | jobs: |
| 14 | star-history: |
| 15 | runs-on: ubuntu-latest |
| 16 | # 网络接口卡住的话不该跑满 GitHub 的六小时上限。翻页 + 画图实测不到一分钟 |
| 17 | timeout-minutes: 10 |
| 18 | steps: |
| 19 | # 图由 `scripts/star-history.mjs` 生成,不再用第三方 action。 |
| 20 | # |
| 21 | # 换掉 `lowlighter/metrics` 有两个理由。一是它把「累计总数」和 |
| 22 | # 「每天新增」绑在同一个开关上,模板里没有只留累计那张的办法, |
| 23 | # 而想要的就是传统的那一条曲线。二是**它是跑在 `contents: write` |
| 24 | # 之下的第三方代码**——这个权限底下跑我们自己的脚本,安心得多。 |
| 25 | - uses: actions/checkout@v4 |
| 26 | |
| 27 | - uses: actions/setup-node@v4 |
| 28 | with: |
| 29 | node-version: 22 |
| 30 | |
| 31 | - name: Render the chart |
| 32 | env: |
| 33 | REPO: ${{ github.repository }} |
| 34 | # **`GITHUB_TOKEN` 在这里不够**:GitHub 在 2026-06-30 把星标 |
| 35 | # 时间线限制成只有仓库的管理员/协作者可读。这个 secret 是一个 |
| 36 | # classic token(fine-grained 的读不了这份数据),已经验过能取到。 |
| 37 | # 名字沿用 `METRICS_TOKEN` 是为了不必再改一次仓库设置 |
| 38 | GITHUB_TOKEN: ${{ secrets.METRICS_TOKEN }} |
| 39 | OUT: chart/star-history.svg |
| 40 | run: node scripts/star-history.mjs |
| 41 | |
| 42 | # **提交到专用的孤儿分支,不碰默认分支。** |
| 43 | # `dev` 上有分支保护(必须走 PR、`enforce_admins: true`),机器人 |
| 44 | # 直推一定被拒;而为了一张图去松保护是本末倒置。`assets` 与 `dev` |
| 45 | # 没有共同历史,在那边提交碰不到任何源码。 |
| 46 | - name: Commit to the assets branch |
| 47 | run: | |
| 48 | set -euo pipefail |
| 49 | git clone --depth 1 --branch assets \ |
| 50 | "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" out |
| 51 | mkdir -p out/assets |
| 52 | # 两张:深色主题用白线那张,浅色用深线那张(README 里 `<picture>` |
| 53 | # 按主题选)。白线在 GitHub 浅色底上是看不见的,所以少一张都不行 |
| 54 | cp chart/star-history.svg chart/star-history-light.svg out/assets/ |
| 55 | cd out |
| 56 | # 星标没变化的那天不留空提交——每天一条 "no change" 会把 |
| 57 | # 这个分支的历史淹掉 |
| 58 | if git diff --quiet -- assets/; then |
| 59 | echo "chart unchanged, nothing to commit" |
| 60 | exit 0 |
| 61 | fi |
| 62 | git config user.name "github-actions[bot]" |
| 63 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 64 | git add assets/ |
| 65 | git commit -m "Star history: $(date -u +%Y-%m-%d)" |
| 66 | git push |