#!/usr/bin/env bash # deploy.sh - Build and deploy to orphan deploy branch # Usage: ./deploy.sh [commit-message] set -e COMMIT_MSG="${1:-Deploy: $(date +'%Y-%m-%d %H:%M:%S')}" echo "๐Ÿ“ฆ Building site on main branch..." bun run build if [ ! -d "build" ]; then echo "โŒ Build failed - build directory not found" exit 1 fi echo "โœ… Build successful" echo "" echo "๐Ÿ”„ Switching to deploy branch..." git checkout deploy echo "๐Ÿงน Cleaning deploy branch (keeping .git and .gitignore)..." # Remove all tracked files except .gitignore git ls-files | grep -v "^\.gitignore$" | xargs -r git rm -f # Remove any untracked files/directories except build/, node_modules/, and .svelte-kit/ find . -mindepth 1 -maxdepth 1 ! -name 'build' ! -name 'node_modules' ! -name '.svelte-kit' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} + echo "๐Ÿ“‹ Copying build output to root..." if [ -d "build" ]; then mv build/* . rm -rf build/ echo "โœ… Build files copied to deploy branch root" else echo "โš ๏ธ No build directory found (this is expected on deploy branch)" fi echo "๐Ÿ“ Staging changes..." git add -A # Check if there are any changes to commit if git diff --staged --quiet; then echo "โ„น๏ธ No changes to deploy" git checkout main exit 0 fi echo "๐Ÿ’พ Committing build artifacts..." git commit -m "$COMMIT_MSG" echo "๐Ÿš€ Pushing to origin/deploy..." git push origin deploy echo "โœ… Switching back to main..." git checkout main echo "" echo "โœจ Deployment complete!" echo " Deploy branch commit: $(git rev-parse --short deploy)" echo " Main branch commit: $(git rev-parse --short main)"