Spaces:
Sleeping
Sleeping
| # push_to_hf.sh — Push current branch to Hugging Face Space main using HF_TOKEN. | |
| # | |
| # Usage: | |
| # bash scripts/push_to_hf.sh | |
| # HF_SPACE_REPO="spaces/ous-sow/sahel-agri-voice" bash scripts/push_to_hf.sh | |
| set -euo pipefail | |
| REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | |
| cd "$REPO_ROOT" | |
| HF_SPACE_REPO="${HF_SPACE_REPO:-spaces/ous-sow/sahel-agri-voice}" | |
| TARGET_BRANCH="${TARGET_BRANCH:-main}" | |
| # Load .env if present and HF_TOKEN is not already exported. | |
| if [[ -z "${HF_TOKEN:-}" && -f "$REPO_ROOT/.env" ]]; then | |
| set -a | |
| # shellcheck disable=SC1091 | |
| source "$REPO_ROOT/.env" | |
| set +a | |
| fi | |
| if [[ -z "${HF_TOKEN:-}" ]]; then | |
| echo "HF_TOKEN is not set." | |
| echo "Set HF_TOKEN in your shell or in .env, then rerun." | |
| exit 1 | |
| fi | |
| CURRENT_BRANCH="$(git branch --show-current)" | |
| if [[ -z "$CURRENT_BRANCH" ]]; then | |
| echo "Could not detect current git branch." | |
| exit 1 | |
| fi | |
| echo "Pushing '$CURRENT_BRANCH' to '$HF_SPACE_REPO' (remote branch: '$TARGET_BRANCH')..." | |
| git push "https://__token__:${HF_TOKEN}@huggingface.co/${HF_SPACE_REPO}" "${CURRENT_BRANCH}:${TARGET_BRANCH}" | |
| echo "Done." | |