-
Notifications
You must be signed in to change notification settings - Fork 1
47 lines (41 loc) · 1.29 KB
/
deploy.yaml
File metadata and controls
47 lines (41 loc) · 1.29 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
name: Deploy mkBlog to server machine
on:
push:
branches:
- main
paths:
- "main.go"
- "go.mod"
- "go.sum"
- "Makefile"
- "config/**"
- "models/**"
- "pkg/**"
- "service/**"
- "utils/**"
- "frontend/**"
- "docker/**"
- "deploy/**"
- ".github/workflows/**"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Prepare deploy key file
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
sed -i 's/\r$//' ~/.ssh/deploy_key || true
chmod 600 ~/.ssh/deploy_key
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add SSH known host
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Update remote repository
run: |
ssh -o BatchMode=yes -i ~/.ssh/deploy_key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \
"cd ${{ secrets.REMOTE_REPO_PATH }} && git fetch origin main && git checkout main && git pull --ff-only origin main"
- name: Build and restart remote service
run: |
ssh -o BatchMode=yes -i ~/.ssh/deploy_key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \
"cd ${{ secrets.REMOTE_REPO_PATH }} && make release"