Skip to content

Commit 041319b

Browse files
committed
feat: add github action
1 parent 87b8a15 commit 041319b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
push:
3+
branches:
4+
- main # 触发分支
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
# - name: Check commit message
11+
# if: contains(github.event.head_commit.message, '[deploy]') == false
12+
# run: |
13+
# echo "Not found keyword '[Deploy]' in commit message. Exiting workflow."
14+
# exit 0
15+
- name: Checkout code # 检查存储库的操作
16+
uses: actions/checkout@v4
17+
18+
- name: Install dependencies and build # 安装依赖,打包
19+
run: |
20+
npx pnpm install
21+
npx pnpm run build
22+
23+
- name: Compressed file # 压缩dist目录下文件和目录
24+
run: |
25+
tar -czf dist.tar.gz -C dist .
26+
27+
- name: Copy file via ssh password # 连接服务器并将压缩包拷贝至指定目录
28+
uses: appleboy/scp-action@v0.1.7
29+
with:
30+
host: ${{ secrets.SERVER_HOST }}
31+
username: ${{ secrets.SERVER_USERNAME }}
32+
password: ${{ secrets.SERVER_PASSWORD }}
33+
port: 22
34+
source: dist.tar.gz
35+
target: /www/wwwroot/50projects-vue3
36+
#
37+
38+
- name: SSH into server and execute commands # 连接服务器并在服务器执行操作
39+
uses: appleboy/ssh-action@master
40+
with:
41+
host: ${{ secrets.SERVER_HOST }}
42+
username: ${{ secrets.SERVER_USERNAME }}
43+
password: ${{ secrets.SERVER_PASSWORD }}
44+
port: 22
45+
script: | # 进入服务器指定目录,删除除压缩包外所有文件,解压并删除压缩包
46+
cd /www/wwwroot/50projects-vue3/
47+
find . -mindepth 1 ! -name 'dist.tar.gz' -exec rm -rf {} +
48+
tar -xzf dist.tar.gz
49+
rm dist.tar.gz

0 commit comments

Comments
 (0)