This repository has been archived on 2026-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Hulumath-Web-Demo/.gitea/workflows/deploy-on-merge.yml
T
Jacky 0df26a370b
PR合并自动部署 / deploy (pull_request) Failing after 2s
v5
2026-08-08 17:27:29 +08:00

54 lines
1.8 KiB
YAML

name: PR合并自动部署
on:
pull_request:
branches: [main]
types: [closed]
jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: 配置SSH环境
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
- name: 远程执行部署
run: |
ssh -i ~/.ssh/deploy_key ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} <<-'EOF'
set -e
cd $DEPLOY_PATH
git config --global --add safe.directory $DEPLOY_PATH
git fetch origin main
# 备份运行时db
if [ -f data/miniapp_v3.db ]; then
cp data/miniapp_v3.db data/miniapp_v3.db.tmp
fi
git checkout origin/main -- .
CHANGED=$(git diff --name-only HEAD FETCH_HEAD | grep "data/miniapp_v3.db" || true)
if [ -z "$CHANGED" ]; then
if [ -f data/miniapp_v3.db.tmp ]; then
cp data/miniapp_v3.db.tmp data/miniapp_v3.db
fi
fi
rm -f data/miniapp_v3.db.tmp
/www/server/pyporject_evn/versions/3.12.13/bin/pip install -r requirements.txt
chown -R www:www .
# 获取gunicorn master进程,发送HUP优雅重载
MASTER_PID=$(pgrep -f "gunicorn_conf.py" -P 1)
echo "Detected gunicorn master PID: $MASTER_PID"
if [ -n "$MASTER_PID" ]; then
kill -HUP "$MASTER_PID"
echo "✅ Graceful reload signal sent"
else
echo "⚠️ Gunicorn master not found, skip reload"
fi
EOF