Update update_clone_badge.yml #24
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: | |
schedule: | |
- cron: '*/5 * * * *' # Runs every 5 minutes | |
push: | |
branches: | |
- v2.1.1-dev | |
jobs: | |
update-badge: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.GH_ACTION }} | |
- 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?per=day&start_date=$(date +%Y-%m-%d)&end_date=$(date +%Y-%m-%d)" \ | |
| 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-)\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.*)|label=Clones-${{ 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 |