generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 26
55 lines (46 loc) · 1.95 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
54
55
name: Update Clone Badge
on:
push:
branches:
- v2.1.1-dev # Specify the branch you want to target here
#schedule:
#- cron: '0 0 * * *' # Runs at midnight every day
jobs:
update-badge:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/v2.1.1-dev' # Run only on v2.2.0-dev branch
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_ACTION }}
ref: v2.1.1-dev # Specify the branch to checkout
- name: Get clone count for today
id: get_clone_count
run: |
# Fetch clone count from GitHub API for today
CLONE_COUNT=$(curl -s -H "Authorization: Bearer ${{ secrets.GH_ACTION }}" \
"https://api.github.com/repos/CDCgov/phoenix/traffic/clones" | jq -r --arg target_day "$(date -d yesterday +%Y-%m-%d)" '.clones[] | select(.timestamp | startswith($target_day))' | jq -r '.count')
echo "CLONE_COUNT=$CLONE_COUNT" >> $GITHUB_ENV
- name: Extract previous clone count from README
id: extract_previous_count
run: |
# Extract previous clone count from README.md
PREVIOUS_COUNT=$(grep -oP '(?<=Clones%3A%20)\d+' README.md)
echo "PREVIOUS_COUNT=$PREVIOUS_COUNT" >> $GITHUB_ENV
- name: Calculate new total clone count
id: calculate_new_total
run: |
# Calculate new total clone count by adding today's count to previous count
NEW_TOTAL=$((PREVIOUS_COUNT + CLONE_COUNT))
echo "NEW_TOTAL=$NEW_TOTAL" >> $GITHUB_ENV
- name: Update README badge
run: |
sed -i "s|\(Clones%3A%20\d\+\)|Clones%3A%20${{ env.NEW_TOTAL }}|" 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 and download counts"
git push