-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (38 loc) · 1.44 KB
/
Copy pathdeploy.yml
File metadata and controls
50 lines (38 loc) · 1.44 KB
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
name: Deploy to production server
run-name: ${{ github.actor }} is deploying blog to production server
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
Deploy:
runs-on: ubuntu-latest
env:
ssh-prefix: ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ubuntu@13.40.196.20
scp-prefix: scp -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -r
temp-dir: /home/ubuntu/blog
prod-dir: /var/www/html/blog
esc-prod-dir: \/var\/www\/html\/blog
steps:
- uses: actions/checkout@v4
- name: Clean install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy to remote server
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan 13.40.196.20 >> ~/.ssh/known_hosts
mv ./public ./blog
${{ env.ssh-prefix }} rm -rf ${{ env.temp-dir }}
${{ env.scp-prefix }} ./blog ubuntu@13.40.196.20:${{ env.temp-dir }}
- name: Check content existence
run: ${{ env.ssh-prefix }} 'if [ -d ${{ env.temp-dir }} ]; then echo "temporal folder is not empty"; else echo "temporal folder is empty"; fi'
- name: Update production folder
run: |
${{ env.ssh-prefix }} sudo rm -rf ${{ env.prod-dir }}
${{ env.ssh-prefix }} sudo mv ${{ env.temp-dir }} ${{ env.prod-dir }}