-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (40 loc) · 1.47 KB
/
clone-stats-and-badge.yml
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
name: Clone Stats and Badge Update
on:
schedule:
- cron: "0 0 * * *" # Run daily at midnight
workflow_dispatch:
jobs:
update-stats-and-badge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup GitHub CLI
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "$GH_TOKEN" | gh auth login --with-token
- name: Get Latest Clone Count
run: |
gh api repos/${{ github.repository }}/traffic/clones > latest_clones.json
- name: Update Historical Data
env:
GIST_ID: ${{ secrets.GIST_ID }}
run: |
gh gist view $GIST_ID > previous_clones.json
jq -s '.[0] * .[1]' previous_clones.json latest_clones.json > clone.json
gh gist edit $GIST_ID clone.json
- name: Push Updated Stats
run: |
gh api -X PUT repos/${{ github.repository }}/traffic/clones --input clone.json
- name: Update README Badge
run: |
CLONE_COUNT=$(cat latest_clones.json | jq '.count')
BADGE_URL="https://img.shields.io/badge/Clones-${CLONE_COUNT}-brightgreen"
sed -i "s|!\[Clone Count\]([^)]*)|![Clone Count](${BADGE_URL})|" README.md
- name: Commit and Push Badge Update
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git add README.md
git commit -m "Update clone count badge"
git push