GitHub 迁移: 更新仓库地址至 fulai-tech/UburPython 并新增转移脚本 (#33) #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy UburNode | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| env: | |
| DEPLOY_DIR: /opt/uburnode | |
| GIT_REPO: https://github.com/fulai-tech/UburPython.git | |
| DEPLOY_BRANCH: main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: uburnode-deploy | |
| cancel-in-progress: true | |
| steps: | |
| - name: Validate required secrets | |
| run: | | |
| test -n "${{ secrets.SSH_HOST }}" || (echo "Missing SSH_HOST" && exit 1) | |
| test -n "${{ secrets.SSH_USER }}" || (echo "Missing SSH_USER" && exit 1) | |
| test -n "${{ secrets.SSH_PRIVATE_KEY }}" || (echo "Missing SSH_PRIVATE_KEY" && exit 1) | |
| - name: Deploy on server | |
| uses: appleboy/ssh-action@v1.2.0 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: ${{ secrets.SSH_PORT || 22 }} | |
| command_timeout: 90m | |
| script: | | |
| set -euo pipefail | |
| DEPLOY_DIR="${{ secrets.DEPLOY_PATH || env.DEPLOY_DIR }}" | |
| GIT_REPO="${{ env.GIT_REPO }}" | |
| DEPLOY_BRANCH="${{ secrets.DEPLOY_BRANCH || env.DEPLOY_BRANCH }}" | |
| if [ ! -d "$DEPLOY_DIR/.git" ]; then | |
| if [ -d "$DEPLOY_DIR" ] && [ -n "$(ls -A "$DEPLOY_DIR" 2>/dev/null)" ]; then | |
| echo "错误: $DEPLOY_DIR 已存在但不是 git 仓库。" | |
| echo "请备份 .env 后: rm -rf $DEPLOY_DIR && git clone -b $DEPLOY_BRANCH $GIT_REPO $DEPLOY_DIR" | |
| exit 1 | |
| fi | |
| mkdir -p "$DEPLOY_DIR" | |
| git clone -b "$DEPLOY_BRANCH" "$GIT_REPO" "$DEPLOY_DIR" | |
| fi | |
| cd "$DEPLOY_DIR" | |
| git fetch --all --prune | |
| git checkout "$DEPLOY_BRANCH" | |
| git pull --ff-only origin "$DEPLOY_BRANCH" | |
| if [ ! -f .env ]; then | |
| echo "缺少 $DEPLOY_DIR/.env,请从 .env.example 复制并填写后重试" | |
| exit 1 | |
| fi | |
| docker compose up -d --build --remove-orphans | |
| docker image prune -f | |
| docker compose ps |