name: Deploy Static Sites

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        run: |
          git clone --depth=1 --branch=${{ github.ref_name }} https://gitea.airlabs.art/${{ github.repository }}.git .

      - name: Sync to server
        run: |
          # 写入 SSH 私钥
          mkdir -p ~/.ssh
          printf '%s\n' '${{ secrets.INTERNAL_SERVER_SSH_KEY }}' > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -H 118.196.70.19 >> ~/.ssh/known_hosts 2>/dev/null

          # 同步所有项目目录到服务器（排除 .gitea、k8s 等非项目目录）
          rsync -avz --delete \
            --exclude='.gitea/' \
            --exclude='.git/' \
            --exclude='k8s/' \
            --exclude='README.md' \
            ./ root@118.196.70.19:/data/static-sites/

          echo "✓ 文件同步完成"

      - name: Verify
        run: |
          ssh root@118.196.70.19 "ls -la /data/static-sites/"
