name: 自动更新代码和重启
on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  update-and-restart:
    runs-on: ubuntu
    steps:
      - name: 同步代码并重启
        run: |
          cd /data/guanghulab/repo
          git fetch origin
          git reset --hard origin/main
          cd /data/guanghulab/repo/server/mcp-server
          npm install --production 2>/dev/null || true
          pm2 restart guanghulab-mcp-server
          cp /data/guanghulab/repo/homepage/fetch_train.py /opt/guanghulab-repo/homepage/fetch_train.py
          cd /opt/guanghulab-repo/homepage
          python3 fetch_train.py
          echo "DONE"
