-
-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (112 loc) · 3.66 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# GitHub Actions References:
# https://docs.github.com/en/actions
name: ⚙🚀
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
jobs:
test_build:
name: ⚛ Test and Build ⚙
strategy:
matrix:
os: [ubuntu-latest]
node: [17.x, "lts/*"]
runs-on: ${{ matrix.os }}
steps:
- name: 🛑 Cancel Previous Running Workflows
uses: styfle/[email protected]
- name: 🛎️ Checkout
uses: actions/[email protected]
- name: 📦 Use Node.js ${{ matrix.node }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node }}
cache: yarn
cache-dependency-path: "**/yarn.lock"
- name: ✨ Install Dependencies
run: yarn --immutable --check-cache
- name: 👓 Run Linter
run: yarn lint
- name: 💅 Run Formatter
run: yarn format
- name: 🧪 Run Tests
run: yarn test
- name: 🛠 Run Build
run: yarn build
- name: ♻ Cache dist Directory for Publish
uses: actions/[email protected]
with:
path: |
./.yarn
./.yarnrc.yml
./dist
./package.json
./pm2.yml
./tsconfig-paths-bootstrap.js
./tsconfig.json
./yarn.lock
key: ${{ github.sha }}-${{ runner.os }}-${{ matrix.node }}
deploy:
name: 🚀 Deploy to Production ✨
needs: test_build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
matrix:
os: [ubuntu-latest]
node: ["lts/*"]
runs-on: ${{ matrix.os }}
steps:
- name: 🛑 Cancel Previous Running Workflows
uses: styfle/[email protected]
- name: ⚙ Configure SSH
env:
SSH_USER: ${{ secrets.PRODUCTION_SSH_USER }}
SSH_HOST: ${{ secrets.PRODUCTION_SSH_HOST }}
SSH_PORT: ${{ secrets.PRODUCTION_SSH_PORT }}
SSH_KEY: ${{ secrets.PRODUCTION_SSH_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat <<EOF >~/.ssh/config
Host production
HostName $SSH_HOST
User $SSH_USER
Port $SSH_PORT
IdentityFile ~/.ssh/production.key
BatchMode yes
StrictHostKeyChecking no
EOF
- name: ♻ Restore dist Directory for Publish
id: restore-dist
uses: actions/[email protected]
with:
path: |
./.yarn
./.yarnrc.yml
./dist
./package.json
./pm2.yml
./tsconfig-paths-bootstrap.js
./tsconfig.json
./yarn.lock
key: ${{ github.sha }}-${{ runner.os }}-${{ matrix.node }}
- name: 🌏 Setup Remote Host ENV
env:
DISCORD_TOKEN: ${{ secrets.PRODUCTION_DISCORD_TOKEN }}
DB_URI: ${{ secrets.PRODUCTION_DB_URI }}
run: |
cat <<EOF >./.env
NODE_ENV=production
DISCORD__BOT_TOKEN=$DISCORD_TOKEN
DB_URI=$DB_URI
PREFIX=
EOF
- name: 🆙 Upload Build State to Remote Host
run: rsync -rltDvzOh --delete ./ production:${{ secrets.PRODUCTION_SSH_PATH }}
- name: ✨ Install Dependencies in Remote Host
run: ssh production 'cd ${{ secrets.PRODUCTION_SSH_PATH }} && yarn workspaces focus --all --production'
- name: 🐥 Run Emperor Ruppy
run: ssh production 'if pm2 describe emperor-ruppy; then pm2 restart emperor-ruppy; else cd ${{ secrets.PRODUCTION_SSH_PATH }} && yarn start; fi'