cicd: fix ssh command by incorrect param position #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Deploy with git" | |
on: | |
push: | |
branches: | |
- main | |
env: | |
SSH_KEY_FILE_DIR: .keys | |
SSH_KEY_FILE_PATH: .keys/deploy_key.pem | |
jobs: | |
ssh_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- 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}} | |
- 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}} -o StrictHostKeyChecking=no ${{secrets.SSH_DEPLOY_USER}}@${{secrets.SSH_DEPLOY_HOST}} "$SSH_COMAND_DEPLOY" | |
- name: Clean deploy key file | |
run: rm -rf ${{env.SSH_KEY_FILE_PATH}} |