-
Notifications
You must be signed in to change notification settings - Fork 8
58 lines (52 loc) · 2.44 KB
/
deploy-dev.yml
File metadata and controls
58 lines (52 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# github actions 中文文档 https://docs.github.com/cn/actions/getting-started-with-github-actions
name: deploy for dev
on:
push:
branches:
- 'dev' # 只针对 dev 分支
paths:
- '.github/workflows/*'
- '__test__/**'
- 'src/**'
- 'Dockerfile'
- 'docker-compose.yml'
- 'bin/*'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: lint and test # 测试
run: |
npm i
npm run lint
npm run test
- name: set ssh key # 临时设置 ssh key
run: |
mkdir -p ~/.ssh/
echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa # secret 在这里配置 https://github.com/imooc-lego/admin-server/settings/secrets
chmod 600 ~/.ssh/id_rsa
ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts
- name: deploy # 部署
run: |
ssh work@182.92.xxx.xxx "
# 【注意】手动创建 /home/work/imooc-lego 目录
# 然后 git clone https://username:password@github.com/imooc-lego/admin-server.git -b dev (私有项目,需要 github 用户名和密码)
# 记得删除 origin ,否则会暴露 github 密码
cd /home/work/imooc-lego/admin-server;
git remote add origin https://wangfupeng1988:${{secrets.WFP_PASSWORD}}@github.com/imooc-lego/admin-server.git;
git checkout dev;
git pull origin dev; # 重新下载最新代码
git remote remove origin; # 删除 origin ,否则会暴露 github 密码
# 启动 docker
docker-compose build admin-server; # 和 docker-compose.yml service 名字一致
docker-compose up -d;
"
- name: delete ssh key # 删除 ssh key
run: rm -rf ~/.ssh/id_rsa