name: Sync SDK Reference

on:
  workflow_dispatch:

permissions:
  contents: write

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

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - uses: dtolnay/rust-toolchain@stable

      - name: Install maturin
        run: pip install maturin

      - name: Build Horizon SDK
        run: |
          python -m venv .venv
          source .venv/bin/activate
          pip install maturin
          maturin develop --features skip-auth

      - name: Generate SDK reference
        run: |
          source .venv/bin/activate
          python tools/generate_sdk_ref.py -o tools/sdk_reference.md

      - name: Commit if changed
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add tools/sdk_reference.md
          git diff --cached --quiet || git commit -m "chore: auto-update SDK reference"
          git push
