Spaces:
Sleeping
Sleeping
File size: 2,797 Bytes
54fe753 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/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 <<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}"
|