name: Update GitHub Pages Stats

on:
  push:
    branches: [main]

permissions:
  contents: write

jobs:
  update-pages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: pip install toml pytest && pip install -e ".[api]" --quiet

      - name: Refresh front door from existing data
        run: |
          agentkit pages-refresh --from-existing-data

      - name: Commit updated pages if changed
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add docs/data.json docs/index.html docs/leaderboard.html
          if git diff --staged --quiet; then
            echo "No changes to commit"
          else
            git commit -m "chore: update GitHub Pages stats [skip ci]"
            git push
          fi
