All checks were successful
Deploy to Server / deploy (push) Successful in 19s
- 创建 deploy.yml 工作流文件,支持自动部署到宿主机 - 使用 runs-on: host 在宿主机上运行 - 自动同步文件、安装依赖并重启 PM2 应用 - 添加部署说明文档
43 lines
1.0 KiB
YAML
43 lines
1.0 KiB
YAML
name: Deploy to Server
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: host
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Copy files to deployment directory
|
|
run: |
|
|
# 创建目标目录(如果不存在)
|
|
mkdir -p /home/score-backend
|
|
|
|
# 使用 rsync 同步文件(排除不需要的文件)
|
|
rsync -av \
|
|
--exclude='.git' \
|
|
--exclude='node_modules' \
|
|
--exclude='.DS_Store' \
|
|
--exclude='*.db' \
|
|
--exclude='bun.lockb' \
|
|
--exclude='.env' \
|
|
--exclude='.env.local' \
|
|
--exclude='.gitea' \
|
|
./ /home/score-backend/
|
|
|
|
- name: Install dependencies
|
|
working-directory: /home/score-backend
|
|
run: |
|
|
bun install
|
|
|
|
- name: Restart PM2 application
|
|
run: |
|
|
cd /home/score-backend
|
|
pm2 restart media-backend || pm2 start main.ts --name media-backend
|