vision_ai / deploy_hf.sh
arvind112's picture
Guard deploy script for unrelated Space history
5f145a2
Raw History Blame Contribute Delete
1.37 kB
#!/usr/bin/env bash
set -e
# Deploy to the Hugging Face Space.
# The Space's git history is unrelated to this repository's `main`, so always
# deploy from `space-deploy`, which was created from `space/main`. Never
# force-push: a fast-forward merge keeps the Space history intact.
#
# The medicine CSV is already tracked with Git LFS, so the one-time
# `git lfs migrate import` step is intentionally NOT rerun here.
SPACE_REMOTE="${SPACE_REMOTE:-space}"
SPACE_BRANCH="${SPACE_BRANCH:-main}"
DEPLOY_BRANCH="${DEPLOY_BRANCH:-space-deploy}"
current_branch=$(git branch --show-current)
if [ "$current_branch" != "$DEPLOY_BRANCH" ]; then
echo "ERROR: run this script from '$DEPLOY_BRANCH' (current: '$current_branch')." >&2
echo "The Space has an unrelated git history; 'git checkout $DEPLOY_BRANCH' first." >&2
exit 1
fi
echo "==> Step 1: Syncing with the Space..."
git fetch "$SPACE_REMOTE" "$SPACE_BRANCH"
git merge --ff-only "$SPACE_REMOTE/$SPACE_BRANCH"
echo "==> Step 2: Committing changes..."
git add -A
git commit -m "${COMMIT_MSG:-Deploy to Hugging Face Space}" || true
echo "==> Step 3: Pushing to ${SPACE_REMOTE} ${DEPLOY_BRANCH}:${SPACE_BRANCH}..."
git push "$SPACE_REMOTE" "$DEPLOY_BRANCH:$SPACE_BRANCH"
echo ""
echo "🎉 Successfully pushed to Hugging Face!"
echo "👉 Check your Space at: https://huggingface.co/spaces/arvind112/vision_ai"