-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (46 loc) · 1.64 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 to Production Server
env:
SERVER_USER: 'swissh'
SERVER_IP: 'swis.sh'
DEPLOY_PATH: '/home/swissh/swis.sh/'
BACKUP_PATH: '/home/swissh/backup.swis.sh/'
on:
push:
branches:
- master # Adjust if your main branch is named differently
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build project
run: bun run build
- name: Set up SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add SSH Key to Known Hosts
run: |
echo "$(ssh-keyscan -t rsa ${{ env.SERVER_IP }} 2>/dev/null)" >> ~/.ssh/known_hosts
- name: Deploy using rsync
run: |
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << EOF
set -euo pipefail
TIMESTAMP=\$(date +%Y%m%d%H%M%S)
# Create backup directory if it doesn't exist
mkdir -p ${{ env.BACKUP_PATH }}
# Backup existing deployment if it exists
if [ -d "${{ env.DEPLOY_PATH }}" ]; then
mv ${{ env.DEPLOY_PATH }} ${{ env.BACKUP_PATH }}/backup-\$TIMESTAMP
fi
# Create new deployment directory
mkdir -p ${{ env.DEPLOY_PATH }}
EOF
rsync -avz --delete .output/public/ ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/