返回 last30days-skill
star-history.yml
根目录 / .github / workflows / star-history.yml
1 name: Update Star History
2
3 # Daily job that fetches stargazers_count via a single GitHub REST call,
4 # appends today's count, renders crisp light/dark SVGs, and pushes them to the
5 # dedicated orphan branch `star-history-assets` so `main` stays commit-free.
6 on:
7 schedule:
8 - cron: "17 6 * * *"
9 workflow_dispatch:
10
11 permissions: {}
12
13 concurrency:
14 group: star-history
15 cancel-in-progress: false
16
17 jobs:
18 update:
19 name: Update star history SVGs
20 runs-on: ubuntu-latest
21 timeout-minutes: 5
22 permissions:
23 contents: write
24 steps:
25 - name: Checkout main
26 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
27 with:
28 persist-credentials: false
29
30 - name: Fetch live stars and publish to assets branch
31 env:
32 GH_TOKEN: ${{ github.token }}
33 REPOSITORY: ${{ github.repository }}
34 ASSETS_BRANCH: star-history-assets
35 run: |
36 set -euo pipefail
37
38 REMOTE_URL="https://x-access-token:${GH_TOKEN}@github.com/${REPOSITORY}.git"
39 ASSETS_DIR="$(mktemp -d)"
40
41 if git ls-remote --exit-code --heads "${REMOTE_URL}" "${ASSETS_BRANCH}" >/dev/null; then
42 git clone --depth 1 --branch "${ASSETS_BRANCH}" "${REMOTE_URL}" "${ASSETS_DIR}"
43 else
44 LOOKUP_STATUS=$?
45 if [ "${LOOKUP_STATUS}" -ne 2 ]; then
46 exit "${LOOKUP_STATUS}"
47 fi
48 git init "${ASSETS_DIR}"
49 git -C "${ASSETS_DIR}" checkout --orphan "${ASSETS_BRANCH}"
50 git -C "${ASSETS_DIR}" remote add origin "${REMOTE_URL}"
51 fi
52
53 python3 .github/scripts/update_star_history.py \
54 --seed .github/data/star-history-seed.json \
55 --data "${ASSETS_DIR}/star-history.json" \
56 --out-light "${ASSETS_DIR}/star-history-light.svg" \
57 --out-dark "${ASSETS_DIR}/star-history-dark.svg" \
58 --repo "${REPOSITORY}" \
59 --fetch
60
61 git -C "${ASSETS_DIR}" config user.name "github-actions[bot]"
62 git -C "${ASSETS_DIR}" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
63 git -C "${ASSETS_DIR}" add star-history.json star-history-light.svg star-history-dark.svg
64
65 if git -C "${ASSETS_DIR}" diff --cached --quiet; then
66 echo "Star history unchanged — nothing to push."
67 exit 0
68 fi
69
70 TODAY="$(date -u +%Y-%m-%d)"
71 git -C "${ASSETS_DIR}" commit -m "chore(stars): update star history (${TODAY})"
72 git -C "${ASSETS_DIR}" push -u origin "${ASSETS_BRANCH}"
73
73 lines YAML