raaf-alpha / scripts /deploy.sh
marvit0's picture
Clean deploy: 2025-05-02T17:27:52
34cc2dc
Raw History Blame Contribute Delete
1.77 kB
#!/usr/bin/env bash
set -euo pipefail
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
# scripts/deploy.sh
# One-step β€œclean” deploy to Hugging Face Spaces.
# This will completely replace the remote history.
# Usage: ./scripts/deploy.sh
# Requires .env at project root with:
# OPENAI_API_KEY=
# HF_USER=
# HF_SPACE=
# HF_TOKEN=
# β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEPLOY_DIR="$REPO_ROOT/hf_space"
# 1) Load environment variables
if [[ -f "$REPO_ROOT/.env" ]]; then
set -o allexport
source "$REPO_ROOT/.env"
set +o allexport
else
echo "❌ .env file not found at $REPO_ROOT/.env"
exit 1
fi
# 2) Authenticate
echo "πŸ”‘ Logging in to Hugging Face..."
huggingface-cli login --token "$HF_TOKEN"
# 3) Wipe any existing local clone
echo "🧹 Removing old hf_space/ (if any)..."
rm -rf "$DEPLOY_DIR"
# 4) Create fresh directory & init git
echo "πŸ“‚ Creating fresh Git repo in hf_space/..."
mkdir -p "$DEPLOY_DIR"
cd "$DEPLOY_DIR"
git init
git remote add origin "https://huggingface.co/spaces/${HF_USER}/${HF_SPACE}.git"
git checkout -b main
# 5) Sync your code (excluding .env and .git)
echo "πŸ”„ Syncing code into hf_space/..."
rsync -av --delete \
--exclude '.git/' \
--exclude '.env' \
"$REPO_ROOT"/ "$DEPLOY_DIR"/
# 6) Commit & force-push as a single β€œclean” commit
echo "πŸ’Ύ Committing and pushing to remote (force)..."
git add .
git commit -m "Clean deploy: $(date +%Y-%m-%dT%H:%M:%S)"
git push origin main --force
echo "πŸš€ Done! Your Space has been reset and updated."