name: Generate README

on:
  push:
    branches:
      - main
    paths:
      - 'apps/**'
      - 'scripts/generate-readme.js'

jobs:
  generate:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: npm ci

      - name: Generate README
        run: node scripts/generate-readme.js

      - name: Commit and push if changed
        run: |
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git add README.md apps.json
          git diff --staged --quiet || git commit -m "docs: regenerate README and apps.json"
          git push
