Files
license-manager/.github/workflows/deploy_backend.git.yml
T
2026-02-10 00:31:03 +08:00

55 lines
1.5 KiB
YAML

name: Deploy Backend via Git
# 触发条件
on:
# 当推送到主分支且修改后端相关文件时自动触发
push:
branches: [ main ]
paths:
- 'backend/**'
- '.github/workflows/deploy_backend.git.yml'
# 支持手动触发
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# 通过SSH连接服务器进行部署
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST43 }}
username: root
password: ${{ secrets.PASS43 }}
port: 22
command_timeout: 10m
script_stop: true
envs: USER
script: |
# 确保使用正确的用户环境(云服务器 root)
export HOME=/root
export USER=root
# 加载 root 用户的环境配置(包括代理设置)
source /root/.bashrc || true
source /root/.profile || true
cd /root/license-manager
echo "Starting git pull with retry (max 5 times)..."
max_retries=5
count=0
until git pull origin main; do
count=$((count + 1))
if [ "$count" -ge "$max_retries" ]; then
echo "❌ git pull failed after $max_retries attempts."
exit 1
fi
echo "⚠️ git pull failed (attempt $count/$max_retries), retrying in 10 seconds..."
sleep 10
done
echo "✅ git pull succeeded."
pm2 restart license_manager