-
-
Notifications
You must be signed in to change notification settings - Fork 20
100 lines (89 loc) · 3.05 KB
/
build-client.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
name: Build & Deploy Website
on:
push:
branches:
- main
paths:
- 'client/**'
- 'docs/**'
workflow_dispatch:
jobs:
build:
name: Build Website
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: Setup Caching
uses: actions/cache@v3
with:
path: |
~/.npm
${{ github.workspace }}/client/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Install Dependencies
run: npm ci --workspace=client --include-workspace-root
- name: Run Linters
run: npm run lint:client && npm run lint:style
- name: Build Site
run: npm run build --workspace=client
env:
API_KEY_GITHUB: ${{ secrets.API_KEY_GITHUB }}
NODE_ENV: production
- name: Compress Assets
uses: stefh/ghaction-CompressFiles@v1
with:
path: ./client/dist
depth: 10
extensions: '.css,.html,.js,.svg,.json'
tools: brotli
- name: Create Deployment Tarball
uses: a7ul/[email protected]
with:
command: c
cwd: ./client/dist
files: .
outPath: pictogrammers-client-${{ github.run_id }}.tar.gz
- name: Upload Tarball Artifact
uses: actions/upload-artifact@v3
with:
name: pictogrammers-client-${{ github.run_id }}
path: pictogrammers-client-${{ github.run_id }}.tar.gz
deploy:
needs: build
name: Deploy Website
runs-on: ubuntu-latest
environment: production
steps:
- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: pictogrammers-client-${{ 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-client-${{ 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
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-client-${{ github.run_id }}.tar.gz -C /opt/${{ secrets.SSH_USER }}/pictogrammers --recursive-unlink
rm /opt/${{ secrets.SSH_USER }}/temp/pictogrammers-client-${{ github.run_id }}.tar.gz