name: Deploy photobooth

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: linux_amd64

    steps:
      - name: Deploy to Debian Server
        uses: appleboy/ssh-action@v1.2.0
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          port: 22
          script: |
            set -eo pipefail

            APP_PATH="/var/www/app/photobooth"
            TEMP_PATH="/tmp/photobooth"

            mkdir -p $APP_PATH

            rm -rf $TEMP_PATH

            git clonehttps://git.sijaarc.xyz/HayemR/photobooth.git $TEMP_PATH

            rsync -avC --delete \
              --no-perms \
              --no-owner \
              --no-group \
              --no-times \
              $TEMP_PATH/ $APP_PATH/

            cd $APP_PATH

            npm install
            npm run build

            pm2 delete photobooth || true
            pm2 serve dist 3000 --name photobooth --spa

            pm2 save
