-
Notifications
You must be signed in to change notification settings - Fork 2
57 lines (49 loc) · 1.72 KB
/
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
name: deploy
on:
push
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: install
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: |
yarn install
- name: build
run: yarn build
- name: get-npm-version
if: github.ref == 'refs/heads/main'
id: package-version
uses: martinbeentjes/[email protected]
- name: Install SSH Key
if: github.ref == 'refs/heads/main'
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: Adding Known Hosts
if: github.ref == 'refs/heads/main'
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy with rsync
if: github.ref == 'refs/heads/main'
run: |
TARGET_DIR="/var/www/html/${{ steps.package-version.outputs.current-version}}"
rsync -a --rsync-path="mkdir -p $TARGET_DIR && rsync" ./build/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$TARGET_DIR
- name: Update symlink
if: github.ref == 'refs/heads/main'
env:
WEB_PATH: "/var/www/html"
run: |
LATEST_PATH="${WEB_PATH}/latest"
VERSIONED_PATH="${WEB_PATH}/${{ steps.package-version.outputs.current-version }}"
rm -f "$LATEST_PATH"
ln -s "$VERSIONED_PATH" "$LATEST_PATH"