name: 重启聊天服务

on:
  push:
    paths:
      - '.runtime/restart-chat-trigger'

jobs:
  restart:
    runs-on: ubuntu
    steps:
      - name: 重启 Portal 聊天服务
        run: |
          echo "═══ 重启 Portal ═══"
          if pm2 describe guanghulab-portal > /dev/null 2>&1; then
            pm2 restart guanghulab-portal
            echo "✅ guanghulab-portal 已重启"
          else
            echo "⚠️  guanghulab-portal 未在 PM2 中注册"
          fi
          
          echo "═══ PM2 状态 ═══"
          pm2 list || true
          
          echo "═══ 验证 ═══"
          sleep 3
          if curl -sf http://127.0.0.1:3000/ > /dev/null 2>&1; then
            echo "✅ Portal 端口 3000 正常"
          else
            echo "❌ Portal 端口 3000 未响应"
          fi
          
          # 尝试重启所有 PM2 服务
          pm2 restart all 2>/dev/null || true
          echo "✅ 所有 PM2 服务已尝试重启"
