name: Deploy to Cloudflare Pages

on:
  push:
    branches: [main]
    paths:
      - "docs/**"
      - ".gitea/workflows/deploy.yaml"
  workflow_dispatch:

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

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2

      - name: Install dependencies
        run: |
          cd docs
          bun install

      - name: Build VitePress
        run: |
          cd docs
          bun run build

      - name: Install Wrangler
        run: npm install -g wrangler

      - name: Deploy to Cloudflare Pages
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
        run: |
          wrangler pages deploy docs/.vitepress/dist \
            --project-name=docs-xcodecli \
            --branch=main \
            --commit-dirty=true
