-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (46 loc) · 2.02 KB
/
clone-tracking.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
48
49
50
51
name: Update Clone Count
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
workflow_dispatch: # Allows manual triggering
jobs:
update-clone-count:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch clone count
id: fetch_count
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
"https://api.github.com/repos/${{ github.repository }}/traffic/clones")
echo "API Response: $response"
today=$(date -u +"%Y-%m-%d")
clone_count=$(echo "$response" | jq --arg today "$today" '.clones[] | select(.timestamp | startswith($today)) | .count')
if [ -z "$clone_count" ]; then
echo "CLONE_COUNT=0" >> $GITHUB_ENV # Default to 0 if no clones today
else
echo "CLONE_COUNT=$clone_count" >> $GITHUB_ENV
fi
echo "API-retrieved clones count for the day ($today): $clone_count"
- name: Update Gist
env:
GIST_ID: 6dc3699f407bffa35cd6670ad08dd307
run: |
gist_content=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
"https://api.github.com/gists/$GIST_ID")
#echo "Gist Response: $gist_content"
current_count=$(echo "$gist_content" | jq -r '.files."clone_count.json".content' | jq '.count' | tr -d '"')
echo "Current clones count from Gist: $current_count"
new_count=$((current_count + CLONE_COUNT))
new_content="{\"count\":$new_count}"
echo "New content: $new_content"
payload=$(jq -n \
--arg content "{\"count\": \"$new_count\"}" \
'{"files": {"clone_count.json": {"content": $content}}}')
echo "Constructed payload: $payload"
curl -X PATCH -H "Authorization: token ${{ secrets.PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "$payload" \
"https://api.github.com/gists/$GIST_ID"