name: update swagger files

on:
  schedule:
    - cron:  '0 */12 * * *' # every 12 hours on the hour
  workflow_dispatch:

jobs:
  update-swagger:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - run: |
          set -euo pipefail

          make update-api-docs

          git config --global user.name "Gitea Bot"
          git config --global user.email "teabot@gitea.io"
          git remote set-url origin https://x-access-token:${{ secrets.DEPLOY_TOKEN }}@gitea.com/gitea/docs.git

          if git status --porcelain | grep -q .; then
            git add --all
            git commit -m "[skip ci] Updated swagger files"
            git push
          else
            echo "No API doc changes detected; skipping commit"
          fi
