Spaces:
Sleeping
Sleeping
| 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 <<JSON | |
| { | |
| "name": "${REPO_NAME}", | |
| "private": $( [[ "${GITHUB_VISIBILITY}" == "private" ]] && echo true || echo false ), | |
| "description": "OpenEnv customer support triage environment", | |
| "auto_init": false | |
| } | |
| JSON | |
| ) | |
| curl -sS -o /tmp/github_repo_create.json -w "%{http_code}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/user/repos \ | |
| -d "${create_payload}" >/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}" | |