name: Deploy to Production (Minified) on: push: branches: [ main, master ] workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest steps: - name: Deploy to production server uses: appleboy/ssh-action@v1.0.3 with: host: ${{ secrets.PROD_HOST }} username: ${{ secrets.PROD_USERNAME }} key: ${{ secrets.PROD_SSH_KEY }} port: ${{ secrets.PROD_PORT || 22 }} script: | # Navigate to project directory cd ${{ secrets.PROD_PROJECT_PATH || '/var/www/portal' }} # Backup current deployment echo "๐Ÿ’พ Creating backup..." cp -r . ../portal-backup-$(date +%Y%m%d_%H%M%S) || true # Pull latest code echo "๐Ÿ”„ Pulling latest code..." git pull origin ${{ github.ref_name }} # Install/Update Composer dependencies for production echo "๐Ÿ“ฆ Installing Composer dependencies..." composer install --no-dev --optimize-autoloader --no-interaction # Install/Update NPM dependencies echo "๐Ÿ“ฆ Installing NPM dependencies..." npm ci --only=production # Build and minify assets echo "๐Ÿ—๏ธ Building and minifying assets..." npm run minify-all # Run database migrations (if needed) echo "๐Ÿ—ƒ๏ธ Running database migrations..." php artisan migrate --force # Laravel optimizations for production echo "โšก Optimizing Laravel for production..." php artisan config:cache php artisan route:cache php artisan view:cache php artisan optimize # Clear all caches echo "๐Ÿงน Clearing caches..." php artisan cache:clear php artisan view:clear php artisan config:clear # Queue restart (if using queues) echo "๐Ÿ”„ Restarting queues..." php artisan queue:restart || true # Set proper permissions echo "๐Ÿ” Setting permissions..." chmod -R 755 storage bootstrap/cache public/uploads chown -R www-data:www-data storage bootstrap/cache public/uploads # Cleanup old backups (keep last 5) echo "๐Ÿงน Cleaning up old backups..." find ../portal-backup-* -maxdepth 0 -type d | sort | head -n -5 | xargs rm -rf || true echo "โœ… Production deployment completed successfully!"