From 7f5370db2a2eb24892bb3cd277b098c2117e171d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:17:54 +0000 Subject: [PATCH 1/2] Initial plan From 1a1802d50653f738db8f44ec4f06a2488c733f8b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:22:52 +0000 Subject: [PATCH 2/2] feat: implement complete GitHub leaderboard automation system Co-authored-by: jaseel0 <225665919+jaseel0@users.noreply.github.com> --- .github/workflows/update-readme.yml | 44 ++++++++++++++++++----------- profile/scripts/package.json | 13 +++++++++ profile/scripts/updateReadme.js | 5 ++-- 3 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 profile/scripts/package.json diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 6c139e6..27bbd22 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -1,40 +1,52 @@ name: Update Org Leaderboard on: - push: - branches: - - main # or your default branch - pull_request: - types: [opened, closed] - issues: - types: [opened, edited, closed] - pull_request_review: - types: [submitted] - workflow_dispatch: # manual trigger + # Run daily at midnight UTC to keep leaderboard up to date + schedule: + - cron: '0 0 * * *' + # Allow manual trigger from the Actions tab + workflow_dispatch: + +# Grant write access so the workflow can commit and push README changes +permissions: + contents: write jobs: update-readme: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '20' + - name: Install dependencies + run: npm install + working-directory: profile/scripts + - name: Generate leaderboard + # GIT_PAT must be added as a repository secret (Settings > Secrets) run: node profile/scripts/updateReadme.js env: - PAT_TOKEN: ${{ secrets.PAT_TOKEN }} + GIT_PAT: ${{ secrets.GIT_PAT }} - name: Commit & push changes env: - PAT_TOKEN: ${{ secrets.PAT_TOKEN }} + GIT_PAT: ${{ secrets.GIT_PAT }} run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - git remote set-url origin https://x-access-token:${PAT_TOKEN}@github.com/${{ github.repository }}.git + # Use GIT_PAT to authenticate push (works for both public and private repos) + git remote set-url origin https://x-access-token:${GIT_PAT}@github.com/${{ github.repository }}.git git add profile/README.md - git commit -m "Update leaderboard" || echo "No changes" - git push origin HEAD:main + # Only commit if there are staged changes; exit gracefully otherwise + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "chore: update leaderboard [skip ci]" + git push origin HEAD:${{ github.event.repository.default_branch }} + fi + diff --git a/profile/scripts/package.json b/profile/scripts/package.json new file mode 100644 index 0000000..6342b99 --- /dev/null +++ b/profile/scripts/package.json @@ -0,0 +1,13 @@ +{ + "name": "leaderboard-scripts", + "version": "1.0.0", + "description": "Scripts for generating the ReactSphere leaderboard", + "main": "updateReadme.js", + "scripts": { + "update": "node updateReadme.js" + }, + "engines": { + "node": ">=20" + }, + "license": "MIT" +} diff --git a/profile/scripts/updateReadme.js b/profile/scripts/updateReadme.js index 0dfd13f..04104cd 100644 --- a/profile/scripts/updateReadme.js +++ b/profile/scripts/updateReadme.js @@ -5,7 +5,8 @@ const https = require('https'); const path = require('path'); const ORG = 'ReactSphere'; -const TOKEN = process.env.PAT_TOKEN; +// Use GIT_PAT secret for GitHub API authentication +const TOKEN = process.env.GIT_PAT; const README_PATH = path.join(__dirname, '..', 'README.md'); const TOP_N = 10; @@ -48,7 +49,7 @@ async function getAllPages(apiPath) { async function main() { if (!TOKEN) { - console.error('PAT_TOKEN is not set'); + console.error('GIT_PAT is not set'); process.exit(1); }