-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (79 loc) · 2.69 KB
/
build-and-deploy.yaml
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
name: Build and deploy
on:
push:
branches: [main, develop]
workflow_dispatch:
jobs:
build:
runs-on: sg
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Restore Cache
id: cache-node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependency
run: npm install
- name: List the state of node modules
if: ${{ steps.cache-node_modules.outputs.cache-hit != 'true' }}
continue-on-error: true
run: npm list
- name: Build
run: npm run build
- name: Archive file
uses: TheDoctor0/[email protected]
with:
filename: thq-${{ github.sha }}.zip
exclusions: '/*node_modules/*'
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: thq-${{ github.sha }}.zip
path: ./thq-${{ github.sha }}.zip
deploy-to-testnet:
runs-on: sg
needs: build
if: ${{ github.ref_name == 'develop' }}
environment: testnet
strategy:
matrix:
target: [SERVER_1, SERVER_2]
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: thq-${{ github.sha }}.zip
- name: Unzip artifact
run: rm -rf ./dist && unzip -q thq-${{ github.sha }}.zip -d ./dist
- name: Deploy to server contract
run: ls -la ./dist && rsync -a ./dist/ ${{ vars[matrix.target] }}:/mnt/ckb/ckb-time-generator
- name: Restart pm2 on server contract
run: ssh ${{ vars[matrix.target] }} 'source ~/.zshrc && cd /mnt/ckb/ckb-time-generator && npm install --omit=dev && npm run reload_testnet'
deploy-to-mainnet:
runs-on: sg
needs: build
if: ${{ github.ref_name == 'main' }}
environment: mainnet
strategy:
matrix:
target: [SERVER_1, SERVER_2]
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: thq-${{ github.sha }}.zip
- name: Unzip artifact
run: rm -rf ./dist && unzip -q thq-${{ github.sha }}.zip -d ./dist
- name: Deploy to server contract
run: ls -la ./dist && rsync -a ./dist/ ${{ vars[matrix.target] }}:/mnt/ckb/ckb-time-generator
- name: Restart pm2 on server contract
run: ssh ${{ vars[matrix.target] }} 'source ~/.zshrc && cd /mnt/ckb/ckb-time-generator && npm install --omit=dev && npm run reload_mainnet'