generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 27
53 lines (44 loc) · 2.18 KB
/
update_clone_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
48
49
50
51
52
53
name: Update Clone Badge
on:
#workflow_dispatch: # Manually trigger workflow
schedule:
- cron: '*/5 * * * *' # Runs every 5 minutes
push:
branches:
- v2.1.1-dev # Specify the branch you want to run the workflow on
#schedule:
# - cron: '0 0 * * *' # Runs at midnight every day
jobs:
update-badge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
node-version: '20.x'
- name: Get clone and download counts
id: get_counts
run: |
# Fetch clone count from GitHub API
CLONE_COUNT=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/CDCgov/phoenix/traffic/clones \
| jq -r '.clones | if . == null then "0" else map(.count) | add | tostring else "0" end')
# Fetch download count from GitHub API (example for fetching release download count)
DOWNLOAD_COUNT=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/CDCgov/phoenix/releases \
| jq -r 'map(.assets | map(select(.download_count != null)) | add | .download_count) | add')
echo "::set-output name=clone_count::$CLONE_COUNT"
echo "::set-output name=download_count::$DOWNLOAD_COUNT"
- name: Update README badge
run: |
# Update clone badge
sed -i "s|\[!\[GitHub Clones\]\(.*\)\]|\[]()|g" README.md
# Update download badge
sed -i "s|\[!\[GitHub Downloads\]\(.*\)\]|\[]()|g" README.md
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "HAISeq"
git add README.md
git commit -m "Update clone badge"
git push