From 691d68c59a0b2253ef6de12af8aabdaa2f2d79d4 Mon Sep 17 00:00:00 2001 From: alboped Date: Fri, 10 Apr 2026 23:10:54 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96ci=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 472832e..d890077 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -6,7 +6,8 @@ # # 部署(推送到 main/master 时):在仓库「工作流 → 密钥」中配置 # SSH_PRIVATE_KEY DEPLOY_HOST DEPLOY_USER DEPLOY_PATH -# DEPLOY_PATH 为 Nginx root,如 /var/www/chat-one-web;rsync 会把 dist/ 下文件同步到该目录。 +# DEPLOY_PATH 为站点父目录;实际发布目录为 ${DEPLOY_PATH}/chat.alboped.com(与 Nginx root 一致)。 +# 使用 tar|ssh 推送,远端无需安装 rsync(rsync 会要求在服务器上也存在 rsync 命令)。 name: CI @@ -56,8 +57,8 @@ jobs: - name: Build run: yarn build - # 直连 deb.debian.org 在国内 Runner 上常极慢或卡住;换镜像并限制超时 - - name: Install rsync and OpenSSH client + # 仅需 SSH 客户端;直连 deb.debian.org 在国内 Runner 上常极慢,换镜像并限制超时 + - name: Install OpenSSH client if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') run: | set -e @@ -71,9 +72,9 @@ jobs: "$f" done apt-get -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 -o Acquire::Retries=2 update - apt-get install -y --no-install-recommends rsync openssh-client + apt-get install -y --no-install-recommends openssh-client - - name: Deploy to Nginx (rsync) + - name: Deploy to Nginx (tar over SSH) if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} @@ -82,12 +83,14 @@ jobs: DEPLOY_PATH: ${{ vars.DEPLOY_PATH }} run: | set -e + : "${DEPLOY_PATH:?DEPLOY_PATH is not set}" + REMOTE_ROOT="${DEPLOY_PATH}/chat.alboped.com" mkdir -p ~/.ssh chmod 700 ~/.ssh echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_deploy chmod 600 ~/.ssh/id_deploy ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts - rsync -avz --delete \ - -e "ssh -i ~/.ssh/id_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" \ - dist/ \ - "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/chat.alboped.com/" + SSH=(ssh -i ~/.ssh/id_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes) + # 清空发布目录再解压,效果类似 rsync --delete;远端只需 tar,无需 rsync + "${SSH[@]}" "${DEPLOY_USER}@${DEPLOY_HOST}" "mkdir -p '${REMOTE_ROOT}' && find '${REMOTE_ROOT}' -mindepth 1 -delete" + tar czf - -C dist . | "${SSH[@]}" "${DEPLOY_USER}@${DEPLOY_HOST}" "tar xzf - -C '${REMOTE_ROOT}'"