Update update_clone_badge.yml #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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|\(label=Clones%3A%20\)\(\d\+\)|\1${{ steps.calculate_new_total.outputs.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 |