Skip to content

Commit 50d9d49

Browse files
authored
Add GitHub Actions workflow for SSH deployment
1 parent 443e98d commit 50d9d49

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/main.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Deploy via SSH
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 或者改为你的主分支名称
7+
workflow_dispatch: # 允许手动触发
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
# 2. 安装pnpm
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v4
19+
with:
20+
version: 10 # 指定pnpm版本,可根据需要调整
21+
22+
# 3. 设置Node.js环境
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '22' # 根据你的项目需求调整版本
27+
cache: 'pnpm'
28+
29+
# 4. 安装依赖
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
# 5. 构建项目
34+
- name: Build project
35+
run: pnpm run build
36+
37+
# 6. 上传构建文件到服务器
38+
- name: Deploy to Server
39+
uses: appleboy/scp-action@master
40+
with:
41+
host: ${{ secrets.REMOTE_HOST }}
42+
username: ${{ secrets.REMOTE_USER }}
43+
key: ${{ secrets.SSH_PRIVATE_KEY }}
44+
port: ${{ secrets.SSH_PORT }}
45+
source: "dist/*" # Vue默认输出目录,根据实际情况调整
46+
target: "/home/srv/tmphr" # 服务器目标路径
47+
strip_components: 1 # 移除dist/前缀
48+
overwrite: true
49+
50+
- name: Deploy to Server
51+
uses: appleboy/ssh-action@v1
52+
with:
53+
host: ${{ secrets.REMOTE_HOST }}
54+
username: ${{ secrets.REMOTE_USER }}
55+
key: ${{ secrets.SSH_PRIVATE_KEY }}
56+
port: ${{ secrets.SSH_PORT }}
57+
script: |
58+
# 在远程服务器上执行的命令
59+
cd ~
60+
date >> ations.log
61+
# ... 其他部署命令 ...

0 commit comments

Comments
 (0)