Spaces:
Sleeping
Sleeping
File size: 1,774 Bytes
34cc2dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #!/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."
|