#!/usr/bin/env bash set -euo pipefail REPO_NAME="${1:-support-triage-openenv}" GITHUB_VISIBILITY="${GITHUB_VISIBILITY:-public}" if [[ -z "${GITHUB_TOKEN:-}" || -z "${GITHUB_USERNAME:-}" ]]; then echo "Missing GITHUB_TOKEN or GITHUB_USERNAME" >&2 exit 1 fi if [[ -z "${HF_TOKEN:-}" || -z "${HF_USERNAME:-}" ]]; then echo "Missing HF_TOKEN or HF_USERNAME" >&2 exit 1 fi if ! command -v huggingface-cli >/dev/null 2>&1; then echo "huggingface-cli is required but not installed." >&2 exit 1 fi # 1) Create GitHub repo via REST API (works without gh CLI) create_payload=$(cat </tmp/github_repo_create_status.txt status_code="$(cat /tmp/github_repo_create_status.txt)" if [[ "${status_code}" != "201" && "${status_code}" != "422" ]]; then echo "GitHub repo creation failed with HTTP ${status_code}" >&2 cat /tmp/github_repo_create.json >&2 exit 1 fi if git remote get-url origin >/dev/null 2>&1; then git remote set-url origin "https://github.com/${GITHUB_USERNAME}/${REPO_NAME}.git" else git remote add origin "https://github.com/${GITHUB_USERNAME}/${REPO_NAME}.git" fi # Authenticated push URL git remote set-url --push origin "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USERNAME}/${REPO_NAME}.git" git push -u origin main # Reset push URL to tokenless remote after push git remote set-url --push origin "https://github.com/${GITHUB_USERNAME}/${REPO_NAME}.git" # 2) Create HF Docker Space repo and push huggingface-cli repo create "${HF_USERNAME}/${REPO_NAME}" \ --repo-type space \ --space_sdk docker \ --token "${HF_TOKEN}" \ --exist-ok >/tmp/hf_repo_create.log if git remote get-url huggingface >/dev/null 2>&1; then git remote set-url huggingface "https://huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}" else git remote add huggingface "https://huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}" fi git remote set-url --push huggingface "https://user:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}" git push -u huggingface main # Reset push URL to tokenless remote after push git remote set-url --push huggingface "https://huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}" echo "Completed." echo "GitHub: https://github.com/${GITHUB_USERNAME}/${REPO_NAME}" echo "HF Space: https://huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}"