tornadomap / deploy.sh
snesbitt's picture
Annual tornado density browser, 1950-2026
3ac20c1
Raw
History Blame Contribute Delete
2.22 kB
#!/usr/bin/env bash
# Deploy this static Space to Hugging Face.
#
# ./deploy.sh <hf-username> <space-name>
#
# Example:
# ./deploy.sh swnesbitt us-tornado-density
#
# Create the Space first at https://huggingface.co/new-space with SDK: Static.
# When git asks for a password, paste a WRITE token from
# https://huggingface.co/settings/tokens (not your account password).
set -euo pipefail
HF_USER="${1:-}"
HF_SPACE="${2:-}"
if [[ -z "$HF_USER" || -z "$HF_SPACE" ]]; then
echo "usage: ./deploy.sh <hf-username> <space-name>" >&2
exit 1
fi
cd "$(dirname "$0")"
echo "==> Deploying $(pwd)"
echo " to https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
echo
# A previous attempt left a half-initialized repo that git cannot reuse, and any
# earlier commit still contains the binaries Hugging Face rejected. Start clean.
if [[ -d .git ]]; then
echo "==> Removing existing .git (starting from a clean history)"
rm -rf .git
fi
echo "==> Building the commit"
git init -q
git add -A
git -c user.email="${GIT_AUTHOR_EMAIL:-$(git config --global user.email || echo you@example.com)}" \
-c user.name="${GIT_AUTHOR_NAME:-$(git config --global user.name || echo deploy)}" \
commit -q -m "Annual tornado density browser, 1950-2026"
git branch -M main
# Guard: nothing binary should reach Hugging Face's pre-receive hook.
echo "==> Checking for files HF would reject"
if git ls-files | grep -qE '\.u8$|\.u16$'; then
echo " ERROR: raw binary arrays are staged; check .gitignore" >&2
exit 1
fi
BIN=0
while IFS= read -r f; do
if LC_ALL=C grep -qI . "$f" 2>/dev/null; then :; else BIN=$((BIN+1)); echo " binary: $f"; fi
done < <(git ls-files)
echo " $(git ls-files | wc -l | tr -d ' ') files staged, $BIN binary"
if [[ $BIN -gt 0 ]]; then
echo " WARNING: binary files present. If the push is rejected, either run" >&2
echo " 'git lfs install' and re-run, or add them to .gitignore." >&2
fi
echo "==> Pushing"
git remote remove hf 2>/dev/null || true
git remote add hf "https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
git push hf main --force
echo
echo "==> Done. Open https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
echo " Hard-refresh with Cmd-Shift-R if it looks stale."