name: Deploy to Production

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    
    steps:
      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.DEPLOY_HOST }}
          username: ${{ secrets.DEPLOY_USERNAME }}
          key: ${{ secrets.DEPLOY_SSH_KEY }}
          port: ${{ secrets.DEPLOY_PORT || 22 }}
          script: |
            export DEPLOY_DIR="${{ secrets.DEPLOY_DIR || '/home/ubuntu/www' }}"
            export SERVICE_NAME="${{ secrets.SERVICE_NAME || 'hoaledgeriq' }}"
            export GIT_BRANCH="${{ secrets.GIT_BRANCH || 'main' }}"
            cd ${{ secrets.DEPLOY_DIR || '/home/ubuntu/www' }}
            ./deploy.sh
