name: Update Star History Chart

on:
  workflow_dispatch:
  schedule:
    # Daily at 06:00 UTC
    - cron: "0 6 * * *"

permissions:
  contents: write

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

      - name: Install SVG renderer
        run: |
          set -euo pipefail
          sudo apt-get update
          sudo apt-get install -y librsvg2-bin

      - name: Fetch latest chart (SVG) and render PNG
        run: |
          set -euo pipefail
          mkdir -p assets
          curl -fsSL \
            "https://api.star-history.com/svg?repos=sickn33/antigravity-awesome-skills&type=date&legend=top-left" \
            -o /tmp/star-history.svg
          rsvg-convert /tmp/star-history.svg -o assets/star-history.png

      - name: Commit and push if changed
        run: |
          set -euo pipefail
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add assets/star-history.png
          if git diff --cached --quiet; then
            echo "No changes in star-history.png"
            exit 0
          fi
          git commit -m "chore: update star history chart"
          git push
