Skip to content

Commit e7d86ee

Browse files
authored
Create update-clone-stats.yml
1 parent b7150c6 commit e7d86ee

File tree

1 file changed

+68
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)