name: Deploy to Production
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: appleboy-ssh-action
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.PROD_HOST }}
          port: ${{ secrets.PROD_PORT }}
          username: ${{ secrets.PROD_USER }}
          key: ${{ secrets.PROD_KEY }}
          script: |
            cd /data/www/bydauto/web-api
            sudo -Hu www-data git pull origin main
            sudo -Hu www-data composer install
            sudo -Hu www-data /usr/local/bin/composer dump-autoload
            sudo -Hu www-data php artisan optimize:clear
            sudo -Hu www-data php artisan optimize
            /usr/bin/supervisorctl reload
