diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4d73df0..8077222 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -131,12 +131,9 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Restart Hugging Face Space - if: success() - run: | - echo "Triggering HF Space restart to pull latest image..." - curl -X POST \ - "https://huggingface.co/api/spaces/${{ vars.HF_SPACE_ID }}/restart" \ - -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)" \ No newline at end of file + # Restart HF Space after successful build + restart-hf-space: + needs: build-and-push + if: success() + uses: ./.github/workflows/hf-space-restart.yml + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/hf-space-restart.yml b/.github/workflows/hf-space-restart.yml new file mode 100644 index 0000000..33ab769 --- /dev/null +++ b/.github/workflows/hf-space-restart.yml @@ -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 +