-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (50 loc) · 2.52 KB
/
update-clone-stats.yml
File metadata and controls
68 lines (50 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Update Clone Stats in README
on:
schedule:
- cron: '0 0 * * 1,5' # Execute every Monday at 00:00 UTC
workflow_dispatch: # Allow manual trigger
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch GitHub clone stats and update README # trigger rescan
env:
MY_PAT: ${{ secrets.MY_PAT }}
REPO: ${{ github.repository }}
run: |
echo "🔑 Using PAT to fetch clone data"
CLONE_DATA=$(curl -s -H "Authorization: token $MY_PAT" \
https://api.github.com/repos/$REPO/traffic/clones)
echo "Debug: CLONE_DATA = $CLONE_DATA"
COUNT=$(echo "$CLONE_DATA" | jq '.count')
UNIQUES=$(echo "$CLONE_DATA" | jq '.uniques')
echo "🔁 Clones: $COUNT, 👤 Unique: $UNIQUES"
BADGE=""
echo "Generated badge: $BADGE"
# Replace the old badge with the new one, regardless of its position in README.md
sed -i 's|!\[Clones\](https://img.shields.io/badge/clones.*)|'"$BADGE"'|' README.md
echo "🔑 Using PAT to fetch visitor data"
VIEW_DATA=$(curl -s -H "Authorization: token $MY_PAT" \
https://api.github.com/repos/$REPO/traffic/views)
echo "Debug: VIEW_DATA = $VIEW_DATA"
COUNT=$(echo "$VIEW_DATA" | jq '.count')
UNIQUES=$(echo "$VIEW_DATA" | jq '.uniques')
echo "👁️ Views: $COUNT, 👤 Unique Visitors: $UNIQUES"
# BADGE=""
BADGE=""
echo "Generated badge: $BADGE"
# Replace the old badge with the new one in README.md (optional: use comment tags)
sed -i 's|!\[Visitors\](https://img.shields.io/badge/visitors.*)|'"$BADGE"'|' README.md
- name: Commit and push if README was updated
env:
MY_PAT: ${{ secrets.MY_PAT }}
run: |
git config --global user.name 'deadislove'
git config --global user.email 'taweilin7689@gmail.com'
git add README.md
git commit -m "Update clone stats" || echo "No changes to commit"
# Use PAT to push changes
REPO_URL="https://x-access-token:${MY_PAT}@github.com/${GITHUB_REPOSITORY}.git"
git push "$REPO_URL" HEAD:main