Update Last Stargazer Badge #9
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 Last Stargazer Badge | |
on: | |
schedule: | |
- cron: "0 * * * *" # Runs hourly | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
update-last-stargazer: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Fetch repository stargazers | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
https://api.github.com/repos/${{ github.repository }}/stargazers \ | |
| jq -r '.[-1].login' > last_stargazer.txt | |
- name: Update README with Badge | |
run: | | |
LAST_STARGAZER=$(cat last_stargazer.txt) | |
BADGE_URL="https://img.shields.io/badge/Last%20Stargazer-${LAST_STARGAZER}-brightgreen?style=flat-square" | |
sed -i.bak -E "s|!\[Last Stargazer\]\(.*\)|![Last Stargazer]($BADGE_URL)|" README.md | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add README.md | |
git commit -m "Update Last Stargazer badge" | |
git push | |