name: Promote staging to production

on:
  workflow_dispatch:

jobs:
  deploy-production:
    runs-on: ubuntu-latest

    steps:
      - name: Copy staging to production and run artisan
        env:
          SFTP_USER: ${{ secrets.SFTP_USERNAME }}
          SFTP_PASS: ${{ secrets.SFTP_PASSWORD }}
        run: |
          sudo apt-get install -y sshpass
          sshpass -p "$SFTP_PASS" ssh -o StrictHostKeyChecking=no \
            $SFTP_USER@ssh.cluster100.hosting.ovh.net \
            "rsync -a \
               --exclude='.env' \
               --exclude='storage/' \
               --exclude='public/storage/' \
               --exclude='vendor/' \
               www-staging/ www/ && \
             cd www && \
             php artisan optimize:clear && \
             ([ -L public/storage ] || (rm -rf public/storage && ln -s ../storage/app/public public/storage)) && \
             php artisan migrate --force && \
             php artisan db:seed --class=InterestTagSeeder --force && \
             php artisan interests:migrate-csv && \
             php artisan config:cache && \
             php artisan route:cache && \
             php artisan view:cache"
