#!/usr/bin/env bash # Deploy this frontend folder to its own HF Space (Etiya/d2l-ui). # # Usage: # ./scripts/deploy-to-hf-space.sh # incremental push # ./scripts/deploy-to-hf-space.sh --create # first-time, create Space then push # # Pre-requisites: # - hf CLI logged in (`hf auth login`) # - Write access to Etiya org # - Run from frontend/ directory set -euo pipefail SPACE_OWNER="Etiya" SPACE_NAME="d2l-ui" REMOTE_URL="https://huggingface.co/spaces/${SPACE_OWNER}/${SPACE_NAME}" # Resolve script-relative paths so the script is location-independent. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" FRONTEND_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" cd "${FRONTEND_DIR}" if [[ "${1:-}" == "--create" ]]; then echo "▶ Creating Space ${SPACE_OWNER}/${SPACE_NAME}…" hf repo create "${SPACE_NAME}" \ --repo-type space \ --space-sdk docker \ --private \ --organization "${SPACE_OWNER}" \ --exist-ok fi # Sanity: ensure SPACE_README.md exists; HF needs the YAML frontmatter. if [[ ! -f SPACE_README.md ]]; then echo "ERROR: SPACE_README.md missing — Space requires it as the deployed README." >&2 exit 1 fi # Stash dev README, swap in SPACE_README, push, restore. TMP_DEV_README="$(mktemp /tmp/dev-readme.XXXXXX.md)" trap 'mv "${TMP_DEV_README}" README.md 2>/dev/null || true' EXIT cp README.md "${TMP_DEV_README}" cp SPACE_README.md README.md # Initialize git remote if needed. if [[ ! -d .git ]]; then echo "▶ Initializing git…" git init -b main >/dev/null git remote add origin "${REMOTE_URL}" fi # If origin remote exists but mismatches, fix. CURRENT_REMOTE="$(git remote get-url origin 2>/dev/null || true)" if [[ "${CURRENT_REMOTE}" != "${REMOTE_URL}" ]]; then if [[ -n "${CURRENT_REMOTE}" ]]; then git remote set-url origin "${REMOTE_URL}" else git remote add origin "${REMOTE_URL}" fi fi # Pull existing remote (if it exists) — handles HF's auto-generated initial commit. git fetch origin main 2>/dev/null || true git pull --rebase origin main 2>/dev/null || true # Stage + commit. node_modules / .next ignored by .gitignore. git add -A if git diff --cached --quiet; then echo "▶ No changes to commit; pushing existing HEAD." else git commit -m "Deploy: $(date -u +%Y-%m-%dT%H:%M:%SZ)" fi echo "▶ Pushing to ${REMOTE_URL}…" git push -u origin main echo "" echo "✓ Done. Build will start automatically. Track at:" echo " ${REMOTE_URL}?logs=build" echo "" echo "Once running, open:" echo " https://etiya-d2l-ui.hf.space" echo "" echo "If you haven't yet: set HF_TOKEN as a Space Secret at" echo " ${REMOTE_URL}/settings"