Update GitHub Stars Count #62
This file contains hidden or 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 GitHub Stars Count | |
| on: | |
| schedule: | |
| # Run daily at 2:00 AM UTC | |
| - cron: '0 2 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-stars: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Fetch GitHub stars | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # List of libp2p repositories to count stars from | |
| REPOS=( | |
| "libp2p/libp2p" | |
| "libp2p/go-libp2p" | |
| "libp2p/rust-libp2p" | |
| "libp2p/js-libp2p" | |
| "libp2p/py-libp2p" | |
| "libp2p/jvm-libp2p" | |
| "vacp2p/nim-libp2p" | |
| "zen-eth/zig-libp2p" | |
| "NethermindEth/dotnet-libp2p" | |
| "Pier-Two/c-libp2p" | |
| "paritytech/litep2p" | |
| "libp2p/specs" | |
| "libp2p/test-plans" | |
| "libp2p/universal-connectivity" | |
| "libp2p/workshop" | |
| "swift-libp2p/swift-libp2p" | |
| ) | |
| TOTAL_STARS=0 | |
| for repo in "${REPOS[@]}"; do | |
| echo "Fetching stars for $repo..." | |
| STARS=$(gh api "repos/$repo" --jq '.stargazers_count' 2>/dev/null || echo "0") | |
| echo " $repo: $STARS stars" | |
| TOTAL_STARS=$((TOTAL_STARS + STARS)) | |
| done | |
| echo "Total stars: $TOTAL_STARS" | |
| # Create static data directory if it doesn't exist | |
| mkdir -p static/data | |
| # Write YAML file | |
| echo "$TOTAL_STARS" > static/data/github-stars | |
| # Display for verification | |
| cat static/data/github-stars | |
| - name: Commit and push if changed | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add static/data/github-stars | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore: update GitHub stars count [skip ci]" | |
| git push | |
| fi |