name: Deploy to Private Server on: push: branches: [ "main" ] jobs: deploy: runs-on: "ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install dependencies run: npm ci - name: Build run: npm run build - name: Verify build output run: | if [ ! -d "dist" ]; then echo "Error: dist directory not found" exit 1 fi - name: Deploy to server run: | DEPLOY_PATH="/var/www/app/vite-app/timelapse-calc" BACKUP_PATH="/var/www/app/vite-app/timelapse-calc.backup" # Create backup if directory exists if [ -d "$DEPLOY_PATH" ]; then echo "Creating backup..." rm -rf "$BACKUP_PATH" mv "$DEPLOY_PATH" "$BACKUP_PATH" fi # Create deployment directory mkdir -p "$DEPLOY_PATH" # Copy new build echo "Deploying new build..." cp -r dist/* "$DEPLOY_PATH/" # Verify deployment if [ $? -eq 0 ]; then echo "Deployment successful!" rm -rf "$BACKUP_PATH" else echo "Deployment failed! Restoring backup..." rm -rf "$DEPLOY_PATH" mv "$BACKUP_PATH" "$DEPLOY_PATH" exit 1 fi