Spaces:
Sleeping
Sleeping
File size: 1,711 Bytes
5181d0e 4f950d0 5181d0e | 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 | #!/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"
|