mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
e8ca5fceb2
Keep README growth data self-hosted and resilient when detailed GitHub stargazer history is unavailable.
93 lines
3.0 KiB
YAML
93 lines
3.0 KiB
YAML
name: Star History
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
schedule:
|
|
- cron: "37 6 * * *"
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- ".github/workflows/star-history.yml"
|
|
- "scripts/star-history/**"
|
|
|
|
permissions: {}
|
|
|
|
concurrency:
|
|
group: star-history
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
publish:
|
|
name: Refresh chart
|
|
if: github.repository == 'bookorbit/bookorbit'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
|
|
with:
|
|
node-version: 24
|
|
|
|
- name: Test generator
|
|
run: node --test scripts/star-history/generate.test.mjs
|
|
|
|
- name: Restore accumulated series
|
|
env:
|
|
SERIES_PATH: ${{ runner.temp }}/star-history.json
|
|
run: |
|
|
if git ls-remote --exit-code --heads origin star-history >/dev/null; then
|
|
git fetch --depth 1 origin \
|
|
'+refs/heads/star-history:refs/remotes/origin/star-history'
|
|
git show origin/star-history:star-history.json > "$SERIES_PATH"
|
|
else
|
|
cp scripts/star-history/bootstrap.json "$SERIES_PATH"
|
|
fi
|
|
|
|
- name: Generate chart
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
STAR_HISTORY_TOKEN: ${{ secrets.STAR_HISTORY_TOKEN }}
|
|
SERIES_PATH: ${{ runner.temp }}/star-history.json
|
|
SVG_PATH: ${{ runner.temp }}/star-history.svg
|
|
run: |
|
|
node scripts/star-history/generate.mjs \
|
|
--repo "$GITHUB_REPOSITORY" \
|
|
--series "$SERIES_PATH" \
|
|
--bootstrap scripts/star-history/bootstrap.json \
|
|
--out "$SVG_PATH"
|
|
|
|
- name: Publish chart and data
|
|
env:
|
|
SERIES_PATH: ${{ runner.temp }}/star-history.json
|
|
SVG_PATH: ${{ runner.temp }}/star-history.svg
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
|
|
json_blob=$(git hash-object -w "$SERIES_PATH")
|
|
svg_blob=$(git hash-object -w "$SVG_PATH")
|
|
tree=$(printf '100644 blob %s\tstar-history.json\n100644 blob %s\tstar-history.svg\n' \
|
|
"$json_blob" "$svg_blob" | git mktree)
|
|
|
|
parent=$(git rev-parse --verify refs/remotes/origin/star-history 2>/dev/null || true)
|
|
if [ -n "$parent" ]; then
|
|
previous_tree=$(git rev-parse "$parent^{tree}")
|
|
if [ "$tree" = "$previous_tree" ]; then
|
|
echo "Star history is unchanged"
|
|
exit 0
|
|
fi
|
|
commit=$(printf '%s\n' "chore: update star history" | \
|
|
TZ=UTC git commit-tree "$tree" -p "$parent")
|
|
else
|
|
commit=$(printf '%s\n' "chore: initialize star history" | \
|
|
TZ=UTC git commit-tree "$tree")
|
|
fi
|
|
|
|
git push origin "$commit:refs/heads/star-history"
|