-
-
Notifications
You must be signed in to change notification settings - Fork 1
36 lines (32 loc) · 1.15 KB
/
deploy_with_git.yml
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
name: "Deploy with git"
on:
push:
branches:
- main
env:
SSH_KEY_FILE_DIR: .keys
SSH_KEY_FILE_PATH: .keys/deploy_key.pem
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Create deploy key file
run: |
mkdir ${{env.SSH_KEY_FILE_DIR}}
echo "${{secrets.SSH_DEPLOY_KEY}}" > ${{env.SSH_KEY_FILE_PATH}}
chmod 600 ${{env.SSH_KEY_FILE_PATH}}
- uses: actions/checkout@v3
- name: Deploy with git
run: |
SSH_COMAND-DEPLOY="cd ${{secrets.SSH_DEPLOY_PATH}} && git pull"
HAS_PYTHON_CHANGE=true
GIT_CHANGED_FILE=$(git show --name-only)
if [[ $(echo $GIT_CHANGED_FILE | grep ".py") == "" ]]; then
HAS_PYTHON_CHANGE=false
fi
if [[ $HAS_PYTHON_CHANGE == true ]]; then
SSH_COMAND-DEPLOY="$SSH_COMAND-DEPLOY && kill $(ps | grep app.py | grep -v grep | awk '{print $2}') && nohup python app.py &"
fi
ssh -i ${{env.SSH_KEY_FILE_PATH}} ${{secrets.SSH_DEPLOY_USER}}@${{secrets.SSH_DEPLOY_HOST}} "$SSH_COMAND-DEPLOY"
- name: Clean deploy key file
run: rm -rf ${{env.SSH_KEY_FILE_PATH}}