Spaces:
Building
Building
Commit ·
c1bb7cf
1
Parent(s): e2c900f
ci: detect HF username and create Space if missing
Browse files- .github/workflows/deploy.yml +19 -2
.github/workflows/deploy.yml
CHANGED
|
@@ -26,9 +26,26 @@ jobs:
|
|
| 26 |
exit 0
|
| 27 |
fi
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
echo "Syncing code to Hugging Face Space: $SPACE_REPO..."
|
| 31 |
-
git push "https://
|
| 32 |
|
| 33 |
echo "Triggering Space restart..."
|
| 34 |
curl -f -s -X POST "https://huggingface.co/api/spaces/${SPACE_REPO}/restart" \
|
|
|
|
| 26 |
exit 0
|
| 27 |
fi
|
| 28 |
|
| 29 |
+
# Detect actual Hugging Face username from token
|
| 30 |
+
HF_USER=$(curl -s -H "Authorization: Bearer ${HF_TOKEN}" https://huggingface.co/api/whoami-v2 | python3 -c "import sys, json; data = json.load(sys.stdin); print(data.get('name', 'rachit-mangawa'))" 2>/dev/null || echo "rachit-mangawa")
|
| 31 |
+
echo "Authenticated as Hugging Face user: $HF_USER"
|
| 32 |
+
|
| 33 |
+
SPACE_REPO="${HF_SPACE:-${HF_USER}/hf-backend}"
|
| 34 |
+
SPACE_NAME="${SPACE_REPO#*/}"
|
| 35 |
+
|
| 36 |
+
# Check if Space exists; create it if missing
|
| 37 |
+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${HF_TOKEN}" "https://huggingface.co/api/spaces/${SPACE_REPO}")
|
| 38 |
+
if [ "$HTTP_STATUS" -eq 404 ]; then
|
| 39 |
+
echo "Space '${SPACE_REPO}' not found. Creating Space with Docker SDK..."
|
| 40 |
+
CREATE_RES=$(curl -s -X POST "https://huggingface.co/api/repos/create" \
|
| 41 |
+
-H "Authorization: Bearer ${HF_TOKEN}" \
|
| 42 |
+
-H "Content-Type: application/json" \
|
| 43 |
+
-d "{\"name\": \"${SPACE_NAME}\", \"type\": \"space\", \"sdk\": \"docker\"}")
|
| 44 |
+
echo "Create response: $CREATE_RES"
|
| 45 |
+
fi
|
| 46 |
+
|
| 47 |
echo "Syncing code to Hugging Face Space: $SPACE_REPO..."
|
| 48 |
+
git push "https://${HF_USER}:${HF_TOKEN}@huggingface.co/spaces/${SPACE_REPO}" main:main --force
|
| 49 |
|
| 50 |
echo "Triggering Space restart..."
|
| 51 |
curl -f -s -X POST "https://huggingface.co/api/spaces/${SPACE_REPO}/restart" \
|