Files
jnss-web/deploy.sh

60 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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)"