name: Deploy to Server

on:
  push:
    branches:
      - main
  
jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Install sshpass
      run: |
        env
        mkdir -p ~/.ssh
        echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan -p 6969 ${{ secrets.HOST }} >> ~/.ssh/known_hosts
        sudo apt-get install sshpass

    - name: Deploy to server
      run: |
        sshpass -p '${{ secrets.SSH_PRIVATE_KEY }}' ssh -v -o StrictHostKeyChecking=no ${{ secrets.USER }}@${{ secrets.HOST }} -p 6969 <<'ENDSSH'
        cd ${{ secrets.WORK_DIR }}
        git pull
        ENDSSH
