#!/usr/bin/env bash # Push the repo to the Hugging Face Space. # # The Space needs YAML frontmatter at the top of README.md; the GitHub README # should not show it. The frontmatter therefore lives in app/space_header.md # and is prepended to README.md on a throwaway branch that is force-pushed to # the Space. Nothing on the local branch changes. # # Usage: # ./scripts/deploy_space.sh [branch] # defaults to the current branch # HF_REMOTE=hf ./scripts/deploy_space.sh # override the git remote name set -euo pipefail REMOTE="${HF_REMOTE:-hf}" BRANCH="${1:-$(git rev-parse --abbrev-ref HEAD)}" TMP_BRANCH="space-deploy-$$" git remote get-url "$REMOTE" >/dev/null git rev-parse --verify "$BRANCH" >/dev/null # Untracked files never reach the Space, so only tracked changes matter here. if [ -n "$(git status --porcelain --untracked-files=no)" ]; then echo "tracked files have uncommitted changes; commit or stash first" >&2 exit 1 fi cleanup() { git switch "$BRANCH" >/dev/null 2>&1 || true git branch -D "$TMP_BRANCH" >/dev/null 2>&1 || true } trap cleanup EXIT # The Space rejects pushes whose metadata is invalid; check locally first. DESC="$(sed -n 's/^short_description: //p' app/space_header.md)" if [ "${#DESC}" -gt 60 ]; then echo "short_description is ${#DESC} chars; the Space allows 60" >&2 exit 1 fi git switch --create "$TMP_BRANCH" "$BRANCH" >/dev/null cat app/space_header.md README.md > README.space mv README.space README.md git add README.md git commit -m "Space build: prepend README frontmatter" >/dev/null git push --force "$REMOTE" "$TMP_BRANCH:main" git lfs push --all "$REMOTE" "$TMP_BRANCH" || true echo "[DONE] pushed $BRANCH -> $REMOTE:main"