name: Sync skill catalogs

# Whenever the MCP source-of-truth changes on master, regenerate the
# skills' offline reference files (catalog.md etc) and push them back
# so the agent-skill bundle stays lockstep with the live API.

on:
  push:
    branches: [master]
    paths:
      - 'tools/lumeo-mcp/src/components-api.json'
      - 'skills/lumeo/gen-catalog.mjs'

permissions:
  contents: write

jobs:
  regen:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          # Need full clone + a PAT-or-default-token with write so we can push back.
          # The default GITHUB_TOKEN works for same-repo pushes provided the
          # `contents: write` permission above is granted.
          token: ${{ secrets.GITHUB_TOKEN }}
          fetch-depth: 0

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

      - name: Regenerate skills/lumeo/references/catalog.md
        run: node skills/lumeo/gen-catalog.mjs

      - name: Commit + push if catalog changed
        run: |
          if git diff --quiet skills/lumeo/references/catalog.md; then
            echo "catalog.md is already in sync — nothing to commit"
            exit 0
          fi

          git config user.name  "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add skills/lumeo/references/catalog.md
          git commit -m "chore(skill-sync): regenerate lumeo skill catalog from components-api.json

          Auto-generated by .github/workflows/sync-skill-catalog.yml whenever
          tools/lumeo-mcp/src/components-api.json changes. Keeps the agent
          skill's offline reference in lockstep with the live MCP API."
          git push origin master
