Spaces:
Runtime error
Runtime error
| name: Keep HF Space Awake | |
| on: | |
| schedule: | |
| # Runs every 13 minutes | |
| - cron: '*/13 * * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| keepalive: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Ping Hugging Face Space | |
| id: ping | |
| run: | | |
| echo "π Pinging Hugging Face Space..." | |
| RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "${{ secrets.HF_SPACE_URL }}") | |
| echo "β Response status: $RESPONSE" | |
| echo "status_code=$RESPONSE" >> $GITHUB_OUTPUT | |
| if [ "$RESPONSE" -ge 200 ] && [ "$RESPONSE" -lt 400 ]; then | |
| echo "β Space is awake!" | |
| echo "success=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "β Space returned status: $RESPONSE" | |
| echo "success=false" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| env: | |
| HF_SPACE_URL: ${{ secrets.HF_SPACE_URL }} | |
| - name: Notify Telegram on failure | |
| if: failure() | |
| run: | | |
| echo "π§ Sending Telegram alert..." | |
| curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
| -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ | |
| -d "text=β οΈ <b>KeepAlive Alert</b>%0A%0Aπ΄ HF Space health check failed!%0A<b>Status:</b> ${{ steps.ping.outputs.status_code }}%0A%0AThe Space might be sleeping or down." \ | |
| -d "parse_mode=HTML" | |
| - name: Notify Telegram on success (after previous failure) | |
| if: success() | |
| run: | | |
| echo "π§ Sending Telegram success notification..." | |
| curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
| -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ | |
| -d "text=β <b>KeepAlive OK</b>%0A%0Aπ’ HF Space health check passed!%0A<b>Status:</b> ${{ steps.ping.outputs.status_code }}%0A%0AThe Space is awake and running." \ | |
| -d "parse_mode=HTML" | |