From 28dbdc04246bf0379be95735e22b82071add0e48 Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Wed, 28 May 2025 10:58:12 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=88=B0=E9=98=BF=E9=87=8C=E4=BA=91ECS?= =?UTF-8?q?=E7=9A=84GitHub=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加新的GitHub工作流文件,用于在代码合并成功后自动构建VitePress文档并部署到阿里云ECS服务器。工作流包括安装依赖、构建项目、通过SSH将构建结果传输到服务器并重启Nginx服务。 --- .github/workflows/auto-deploy-to-aliyun.yml | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/auto-deploy-to-aliyun.yml diff --git a/.github/workflows/auto-deploy-to-aliyun.yml b/.github/workflows/auto-deploy-to-aliyun.yml new file mode 100644 index 0000000..7008f5f --- /dev/null +++ b/.github/workflows/auto-deploy-to-aliyun.yml @@ -0,0 +1,41 @@ +name: Deploy to Aliyun ECS after Merge +on: + workflow_run: + workflows: ['Auto Merge aliyun'] # 监听名为 "Auto Merge aliyun" 的工作流的运行结果 + types: + - completed +jobs: + deploy: + # 只有当合并工作流成功完成时才运行部署工作流 + if: github.event.workflow_run.conclusion =='success' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # 如果未启用 lastUpdated,则不需要 + - uses: pnpm/action-setup@v3 + with: + version: 9 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: pnpm + - name: Install dependencies + run: pnpm i + - name: Build with VitePress + run: pnpm run docs:build + - name: Deploy to ECS + uses: appleboy/ssh-action@v0.1.0 # 使用 ssh-action 将文件传输并部署到服务器 + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} # 从 Secrets 中获取 SSH 密码 + script: | + # 创建或确保目标目录存在 + mkdir -p /usr/share/nginx/html + # 将本地构建的 dist 目录内容复制到服务器的 nginx html 目录 + scp -r ${{ github.workspace }}/docs/.vitepress/dist/* ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_IP }}:/usr/share/nginx/html/ + # 重启 nginx 服务 + sudo systemctl restart nginx