unibest/.github/workflows/auto-deploy-to-aliyun.yml
feige996 28dbdc0424 ci: 添加自动部署到阿里云ECS的GitHub工作流
添加新的GitHub工作流文件,用于在代码合并成功后自动构建VitePress文档并部署到阿里云ECS服务器。工作流包括安装依赖、构建项目、通过SSH将构建结果传输到服务器并重启Nginx服务。
2025-05-28 10:58:12 +08:00

42 lines
1.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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