# ═══════════════════════════════════════════════
# 🔺 Sovereign: TCS-0002∞ | Root: SYS-GLW-0001
# 📜 Copyright: 国作登字-2026-A-00037559
# ═══════════════════════════════════════════════
name: 🌀 光湖灯塔 · GitHub Pages 部署

on:
  push:
    branches:
      - main          # 仅 main 分支触发生产部署
    paths:
      - 'docs/**'
      - 'CNAME'
      - 'persona-studio/frontend/**'
      - '.github/brain/**'
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Pages
        uses: actions/configure-pages@v5

      - name: Prepare deployment artifacts
        run: |
          # Sync Persona Studio frontend
          mkdir -p docs/persona-studio
          if [ -d "persona-studio/frontend" ]; then
            cp -r persona-studio/frontend/* docs/persona-studio/
          fi
          # Ensure CNAME is in docs for custom domain (single source of truth from root CNAME)
          if [ -f "CNAME" ]; then
            cp CNAME docs/CNAME
          fi

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: docs/

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
