separate action for manual invocation

This commit is contained in:
Gamosoft 2025-12-07 16:54:10 +01:00
parent 87f5aa112d
commit 0203cd7a56
2 changed files with 49 additions and 9 deletions

View File

@ -131,12 +131,9 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Restart Hugging Face Space # Restart HF Space after successful build
if: success() restart-hf-space:
run: | needs: build-and-push
echo "Triggering HF Space restart to pull latest image..." if: success()
curl -X POST \ uses: ./.github/workflows/hf-space-restart.yml
"https://huggingface.co/api/spaces/${{ vars.HF_SPACE_ID }}/restart" \ secrets: inherit
-H "Authorization: Bearer ${{ secrets.HF_TOKEN }}" \
-H "Content-Type: application/json" \
--fail-with-body || echo "HF Space restart failed (Space may not exist or token invalid)"

43
.github/workflows/hf-space-restart.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Restart Hugging Face Space
on:
# Can be called from other workflows
workflow_call:
# Can be triggered manually
workflow_dispatch:
jobs:
restart-space:
runs-on: ubuntu-latest
steps:
- name: Restart Hugging Face Space
run: |
echo "Triggering HF Space restart to pull latest image..."
if [ -z "${{ vars.HF_SPACE_ID }}" ]; then
echo "::warning::HF_SPACE_ID variable not set. Skipping HF restart."
exit 0
fi
if [ -z "${{ secrets.HF_TOKEN }}" ]; then
echo "::warning::HF_TOKEN secret not set. Skipping HF restart."
exit 0
fi
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
"https://huggingface.co/api/spaces/${{ vars.HF_SPACE_ID }}/restart" \
-H "Authorization: Bearer ${{ secrets.HF_TOKEN }}" \
-H "Content-Type: application/json")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "✅ HF Space restart triggered successfully!"
echo "Space: ${{ vars.HF_SPACE_ID }}"
else
echo "::warning::HF Space restart failed (HTTP $HTTP_CODE)"
echo "Response: $BODY"
echo "Space may not exist or token may be invalid."
fi