Update Sponsors #104
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 Sponsors | |
| on: | |
| workflow_dispatch: # Manual trigger | |
| schedule: | |
| - cron: "0 0 * * *" # Daily automatic update | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-sponsors: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ssh-key: ${{ secrets.DEPLOY_KEY }} | |
| - name: Setup environment | |
| run: sudo apt-get install -y jq | |
| - name: Fetch sponsors | |
| id: fetch-sponsors | |
| run: | | |
| SPONSORS_JSON=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \ | |
| -X POST -d '{ | |
| "query": "query { user(login:\"${{ github.repository_owner }}\") { sponsorshipsAsMaintainer(first: 100) { nodes { sponsor { login, avatarUrl, url } } } } }" | |
| }' https://api.github.com/graphql) | |
| # Save sponsors as markdown table (avatar and login with hyperlink) | |
| echo "## 🎗️ Sponsors" > sponsors.md | |
| echo "" >> sponsors.md | |
| echo "| Avatar | Sponsor |" >> sponsors.md | |
| echo "| ------ | ------- |" >> sponsors.md | |
| echo "$SPONSORS_JSON" | jq -r '.data.user.sponsorshipsAsMaintainer.nodes[] | | |
| "| [&s=150)](\(.sponsor.url)) | [\(.sponsor.login)](\(.sponsor.url)) |"' >> sponsors.md | |
| echo "" >> sponsors.md | |
| echo "❤️ Thank you for your support!" >> sponsors.md | |
| # Count sponsors for conditional update | |
| SPONSOR_COUNT=$(echo "$SPONSORS_JSON" | jq '.data.user.sponsorshipsAsMaintainer.nodes | length') | |
| echo "sponsor_count=$SPONSOR_COUNT" >> $GITHUB_OUTPUT | |
| - name: Update README | |
| if: steps.fetch-sponsors.outputs.sponsor_count > 0 | |
| run: | | |
| if [ -s sponsors.md ]; then | |
| echo "Found sponsors data:" | |
| cat sponsors.md | |
| # Create a temporary README with updated sponsors | |
| awk -v new_content="$(cat sponsors.md)" ' | |
| BEGIN { in_sponsor_section = 0; printed = 0 } | |
| /<!-- sponsors-start -->/ { | |
| print; | |
| in_sponsor_section = 1 | |
| if (!printed) { | |
| print new_content | |
| printed = 1 | |
| } | |
| next | |
| } | |
| /<!-- sponsors-end -->/ { | |
| in_sponsor_section = 0 | |
| } | |
| !in_sponsor_section { print } | |
| ' README.md > README.tmp && mv README.tmp README.md | |
| echo "--- Updated README Preview ---" | |
| grep -A15 "Sponsors" README.md || echo "Sponsors section not found" | |
| else | |
| echo "No sponsors data found in sponsors.md" | |
| exit 0 | |
| fi | |
| - name: Commit changes | |
| if: steps.fetch-sponsors.outputs.sponsor_count > 0 | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "[email protected]" | |
| git add README.md | |
| git diff --cached --quiet || git commit -m "Update sponsors [skip ci]" | |
| git push |