Skip to content

Update Stargazers

Update Stargazers #16

Workflow file for this run

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'