-
Notifications
You must be signed in to change notification settings - Fork 47
76 lines (70 loc) · 1.96 KB
/
ci_cd.yml
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: ci_cd
on:
push:
branches:
- main
env:
SSH_HOST: ${{secrets.SSH_HOST}}
SSH_USERNAME: ${{secrets.SSH_USERNAME}}
DEPLOY_DIR: ${{secrets.DEPLOY_DIR}}
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '12.x'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
# 缓存命中
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
# 存储key
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependency
run: |
yarn config set registry https://registry.npmmirror.com
yarn
- name: Build
run: yarn build
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
#产物名称
name: artifact
#产物路径
path: dist
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download production artifacts
uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- name: SSH Auth && Deploy To the Server
run: |
ssh -V
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "PubkeyAcceptedKeyTypes +ssh-rsa" > ~/.ssh/config
ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
cat ~/.ssh/known_hosts
cat ~/.ssh/config
ls dist
scp -r dist/* $SSH_USERNAME@$SSH_HOST:$DEPLOY_DIR