-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (81 loc) · 2.53 KB
/
prod-server-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
77
78
79
80
81
82
83
84
name: Production Server CD
on:
push:
branches:
- main
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
src/**/*.+(ts|tsx)
FILES: |
package.json
RELATIVE: "server"
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_HOST: ${{ secrets.HOSTNAME }}
SSH_USER: ${{ secrets.USERNAME }}
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Checkout and Pull origin
run: ssh production 'cd ~/store-4 && git checkout main && git pull origin'
- name: if changed dependencies, install dependencies
run: ssh production 'cd ~/store-4/server && npm i'
if: env.MATCHED_FILES
- name: Reload Pm2
run: ssh production 'cd ~/store-4/server && npm run build && sudo pm2 reload store-4'
if: env.GIT_DIFF
frontend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
client/src/**/*.+(ts|tsx)
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_HOST: ${{ secrets.HOSTNAME }}
SSH_USER: ${{ secrets.USERNAME }}
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Touch .env file
run: |
cat >>./.env <<END
SERVER_URL=${{ secrets.SERVER_URL }}
END
working-directory: client
- name: Run build script && Sync build files to server
run: cd client && npm i && npm run build && rsync -avz ./dist/ production:~/store-4/client/dist
if: env.GIT_DIFF