diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f82420..1d47464 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,96 +5,27 @@ on: branches: [ main ] pull_request: branches: [ main ] + workflow_dispatch: + inputs: + reason: + description: '手动触发部署的原因' + required: false + default: '手动部署' jobs: deploy: runs-on: ubuntu-latest - environment: SSH-KEY steps: - uses: actions/checkout@v4 - name: 安装依赖工具 run: sudo apt-get install -y sshpass expect - - name: 创建部署脚本 - run: | - cat > deploy.sh << 'EOF' - #!/usr/bin/expect -f - set timeout 60 - - # 连接服务器 - spawn ssh -o StrictHostKeyChecking=no -p 42422 $env(SERVER_USER)@$env(SERVER_ADDRESS) - - # 处理普通密码提示 - expect { - "Password:" { - send "$env(SERVER_PASSWORD)\r" - } - } - - # 等待登录成功 - expect "$ " - - # 关闭服务 - send "sudo systemctl stop neobot.service\r" - expect { - "Password:" { - send "$env(SERVER_PASSWORD)\r" - exp_continue - } - "$ " {} - } - - # 拉取最新代码 - send "cd /home/luoxiaolei/neobot/NeoBot && git pull origin main\r" - expect { - "error:" { - send_user "代码拉取失败!\n" - exit 1 - } - "$ " {} - } - - # 重启服务 - send "sudo systemctl start neobot.service\r" - expect { - "Password:" { - send "$env(SERVER_PASSWORD)\r" - exp_continue - } - "$ " {} - } - - # 检查服务状态 - send "sudo systemctl status neobot.service\r" - expect { - "active (running)" { - send_user "服务重启成功!\n" - } - "failed" { - send_user "服务启动失败!\n" - exit 1 - } - } - - # 退出 - send "exit\r" - - expect eof - EOF - chmod +x deploy.sh - - name: 执行部署 run: | - export SERVER_USER="${{ secrets.SERVER_USER }}" - export SERVER_ADDRESS="${{ secrets.SERVER_ADDRESS }}" - export SERVER_PASSWORD="${{ secrets.SERVER_PASSWORD }}" - ./deploy.sh + sshpass -p "${{ secrets.SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p 42422 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_ADDRESS }} 'sudo systemctl stop neobot.service && cd /home/luoxiaolei/neobot/NeoBot && git pull origin main && sudo systemctl start neobot.service' continue-on-error: true - - name: 清理脚本 - run: rm deploy.sh - - name: 检查部署状态 if: failure() run: |