#!/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 / # # 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 /}" : "${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}"