File size: 1,270 Bytes
9580dce | 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 | #!/usr/bin/env bash
# Push the current commit to a Hugging Face Docker Space.
#
# Usage:
# export HF_TOKEN=hf_xxx # a WRITE token
# scripts/deploy-hf.sh <user>/<space>
#
# Snapshots the current git commit, swaps in the front-matter README the Space
# needs, and force-pushes it to the Space's main branch. The Space must already
# exist (create it once with Docker SDK — see deploy/huggingface/DEPLOY.md).
set -euo pipefail
SPACE="${1:?usage: deploy-hf.sh <user>/<space>}"
: "${HF_TOKEN:?set HF_TOKEN to a Hugging Face write token}"
ROOT="$(git rev-parse --show-toplevel)"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
# Clean snapshot of the tracked files at HEAD (no node_modules, .next, dev.db).
git -C "$ROOT" archive --format=tar HEAD | tar -x -C "$TMP"
# The Space root README must carry the docker/app_port YAML front matter.
cp "$ROOT/deploy/huggingface/README.md" "$TMP/README.md"
cd "$TMP"
git init -q
git add -A
git -c user.email=deploy@local -c user.name=deploy commit -qm "Deploy RotNot"
git branch -M main
echo "→ Pushing to https://huggingface.co/spaces/${SPACE}"
git push --force "https://user:${HF_TOKEN}@huggingface.co/spaces/${SPACE}.git" main
echo "✓ Pushed. The Space is building at https://huggingface.co/spaces/${SPACE}"
|