name: Deploy Admin

on:
  push:
    branches: [main]
    paths:
      - "apps/admin/**"
      - "packages/shared-types/**"
      - "packages/ui/**"
      - ".github/workflows/deploy-admin.yml"
  workflow_dispatch:

concurrency:
  group: deploy-admin-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Build Admin
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9.15.2

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

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build workspace
        run: pnpm run build

  deploy:
    name: Deploy Admin (Template)
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Trigger deployment webhook
        env:
          ADMIN_DEPLOY_WEBHOOK_URL: ${{ secrets.ADMIN_DEPLOY_WEBHOOK_URL }}
        run: |
          if [ -z "$ADMIN_DEPLOY_WEBHOOK_URL" ]; then
            echo "ADMIN_DEPLOY_WEBHOOK_URL is not configured. Skipping deploy."
            exit 0
          fi

          curl -X POST "$ADMIN_DEPLOY_WEBHOOK_URL"
          echo "Admin deployment webhook triggered."
