Update Stargazers #16
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 Stargazers | |
| on: | |
| schedule: | |
| - cron: '0 */12 * * *' # Every 12 hours | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| update-stargazers: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Fetch and Update Stargazers | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const owner = 'CodeNKoffee'; | |
| const repo = 'leads-intercontinental'; | |
| const { data: stargazers } = await github.rest.activity.listStargazersForRepo({ | |
| owner, | |
| repo, | |
| per_page: 30 | |
| }); | |
| if (stargazers.length === 0) { | |
| console.log('No stargazers found yet.'); | |
| return; | |
| } | |
| let gridHtml = '<table><tr>'; | |
| stargazers.forEach((stargazer, index) => { | |
| const user = stargazer.user || stargazer; | |
| if (index > 0 && index % 10 === 0) gridHtml += '</tr><tr>'; | |
| gridHtml += ` | |
| <td align="center"> | |
| <a href="${user.html_url}" title="${user.login}"> | |
| <img src="https://images.weserv.nl/?url=${user.avatar_url}&w=50&h=50&fit=cover&mask=circle" width="50" height="50" style="display: block;" alt="${user.login}"/> | |
| </a> | |
| </td>`; | |
| }); | |
| gridHtml += '</tr></table>'; | |
| const readmePath = 'README.md'; | |
| let readme = fs.readFileSync(readmePath, 'utf8'); | |
| const startMarker = '<!-- STARGAZERS_START -->'; | |
| const endMarker = '<!-- STARGAZERS_END -->'; | |
| const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`, 'g'); | |
| readme = readme.replace(regex, `${startMarker}\n${gridHtml}\n${endMarker}`); | |
| fs.writeFileSync(readmePath, readme); | |
| - name: Commit Changes | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "docs: update stargazers grid [skip ci]" | |
| file_pattern: 'README.md' |