-
-
Notifications
You must be signed in to change notification settings - Fork 20
91 lines (79 loc) · 2.6 KB
/
build-api.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
name: Build & Deploy API
on:
push:
branches:
- main
paths:
- 'api/**'
workflow_dispatch:
jobs:
build:
name: Build API
runs-on: ubuntu-latest
environment: production
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install Dependencies
run: npm ci --workspace=api --include-workspace-root
- name: Run ESLint
run: npm run lint:api
- name: Build API
run: npm run build --workspace=api
env:
NODE_ENV: production
- name: Prune dev dependencies
run: npm prune --omit=dev
- name: Move node_modules
run: cp -nr node_modules/* api/node_modules
- name: Create Deployment Tarball
uses: a7ul/[email protected]
with:
command: c
cwd: ./api
files: |
./dist
./package.json
./node_modules
outPath: pictogrammers-api-${{ github.run_id }}.tar.gz
- name: Upload Tarball Artifact
uses: actions/upload-artifact@v3
with:
name: pictogrammers-api-${{ github.run_id }}
path: pictogrammers-api-${{ github.run_id }}.tar.gz
deploy:
needs: build
name: Deploy API
runs-on: ubuntu-latest
environment: production
steps:
- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: pictogrammers-api-${{ github.run_id }}
- name: Deploy Tarball to Server
uses: trendyminds/github-actions-rsync@master
with:
RSYNC_OPTIONS: -avzr --delete
RSYNC_TARGET: /opt/${{ secrets.SSH_USER }}/temp
RSYNC_SOURCE: /pictogrammers-api-${{ github.run_id }}.tar.gz
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USER }}
SSH_HOSTNAME: ${{ secrets.SSH_HOST }}
- name: Expand Tarball & Restart API
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
tar -zxf /opt/${{ secrets.SSH_USER }}/temp/pictogrammers-api-${{ github.run_id }}.tar.gz -C /opt/${{ secrets.SSH_USER }}/pictogrammers-api --recursive-unlink
rm /opt/${{ secrets.SSH_USER }}/temp/pictogrammers-api-${{ github.run_id }}.tar.gz
sudo pm2 restart pictogrammers-api