name: Update Plans Data

on:
  schedule:
    - cron: '0 * * * *'  # Every hour
  workflow_dispatch:

permissions:
  contents: write

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
          cache-dependency-path: docs/package-lock.json

      - name: Install dependencies
        run: npm ci
        working-directory: docs

      - name: Update plans data
        run: npm run update:plans
        working-directory: docs

      - name: Commit if changed
        run: |
          git diff --quiet docs/public/data/plans.json && echo "No changes" && exit 0
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add docs/public/data/plans.json
          git commit -m "chore: update plans data [skip ci]"
          git push
