-
Notifications
You must be signed in to change notification settings - Fork 2
56 lines (48 loc) · 1.8 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
name: deploy
on:
- push
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build
run: |
ls -la
yarn install
yarn build
- name: get-npm-version
id: package-version
uses: martinbeentjes/[email protected]
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: 'sandwiches'
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
# - name: check if remote file exists
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.SSH_HOST }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}git
# port: ${{ secrets.SSH_PORT }}
# script: |
# if [ -f /var/www/html/${{ steps.package-version.outputs.current-version}} ]; then
# exists=yes
# else
# exists=no
# fi
# echo "EXISTS=$exists" >> "$GITHUB_OUTPUT"
# - name: fail if version exists
# if: ${{ steps.version-exists.outputs.EXISTS == 'yes' }}
# uses: actions/github-script@v3
# with:
# script: |
# core.setFailed('/var/www/html/${{ steps.package-version.outputs.current-version}} already exists')
- name: Deploy with rsync
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
run: sudo ln -sf /var/www/html/${{ steps.package-version.outputs.current-version}} /var/www/html/latest