plane-mode-scholar / scripts /push_hf_space.sh
PMS Sync
Deploy 000b308 (flattened for HF Spaces)
4577459
Raw
History Blame Contribute Delete
2.01 kB
#!/usr/bin/env bash
# Hard-push GitHub HEAD → Hugging Face Spaces (flattened single commit).
# Pushes to personal Space and build-small-hackathon org submission Space.
# Requires a Hugging Face token from the Space owner account (GuusBouwensNL).
#
# Usage:
# export HF_TOKEN=hf_... # write access, GuusBouwensNL account
# ./scripts/push_hf_space.sh
set -euo pipefail
HF_USER="${PMS_HF_USER:-GuusBouwensNL}"
SPACES=(
"build-small-hackathon/plane-mode-scholar"
"GuusBouwensNL/plane-mode-scholar"
)
if [[ -z "${HF_TOKEN:-}" ]]; then
echo "ERROR: Set HF_TOKEN (write token for ${HF_USER})"
echo " export HF_TOKEN=hf_..."
exit 1
fi
# Trim accidental whitespace/newlines from pasted tokens
HF_TOKEN="$(printf '%s' "$HF_TOKEN" | tr -d '\n\r ')"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
SHA=$(git rev-parse --short HEAD)
ORIG_BRANCH=$(git rev-parse --abbrev-ref HEAD)
cleanup() {
git checkout -f "$ORIG_BRANCH" >/dev/null 2>&1 || true
git branch -D hf-deploy >/dev/null 2>&1 || true
}
trap cleanup EXIT
git config user.email "sync@plane-mode-scholar"
git config user.name "PMS Sync"
git checkout --orphan hf-deploy
git add -A
git commit -q -m "Deploy $SHA (flattened for HF Spaces)"
push_space() {
local repo="$1"
local url="https://${HF_USER}:${HF_TOKEN}@huggingface.co/spaces/${repo}"
echo "Force-pushing $SHA → https://huggingface.co/spaces/${repo}"
for attempt in 1 2 3 4 5; do
if git push --force "$url" hf-deploy:main; then
return 0
fi
echo "Push failed, retry in $((attempt * 4))s..."
sleep $((attempt * 4))
done
echo "ERROR: push to ${repo} failed after 5 attempts"
return 1
}
for repo in "${SPACES[@]}"; do
push_space "$repo"
done
echo "Done. Both Spaces will rebuild in 2–5 min."
python3 scripts/verify_org_space.py || true
echo "Verify README: https://huggingface.co/spaces/build-small-hackathon/plane-mode-scholar"
echo "Health: curl -s https://build-small-hackathon-plane-mode-scholar.hf.space/api/health"