Archived
36 lines
1.1 KiB
YAML
36 lines
1.1 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 ${{ secrets.DEPLOY_PATH }}
|
|
git config --global --add safe.directory ${{ secrets.DEPLOY_PATH }}
|
|
git pull origin main
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
chown -R www:www .
|
|
PID=\$(pgrep -f "gunicorn_conf.py" | head -1)
|
|
if [ -n "\$PID" ]; then
|
|
echo "重启gunicorn pid: \$PID"
|
|
kill -HUP \$PID
|
|
else
|
|
echo "未找到gunicorn进程,跳过HUP重启"
|
|
fi
|
|
EOF |