Restart Koyeb Service #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Restart Koyeb Service | |
| on: | |
| workflow_run: | |
| workflows: ["Build and push Docker images"] | |
| types: | |
| - completed | |
| jobs: | |
| koyeb: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Restart Koyeb Service | |
| env: | |
| KOYEB_API_TOKEN: ${{ secrets.KOYEB_API_TOKEN }} | |
| KOYEB_SERVICE_ID: ${{ secrets.KOYEB_SERVICE_ID }} | |
| run: | | |
| echo "🚀 Preparing to restart Koyeb service..." | |
| REQUIRED=(KOYEB_API_TOKEN KOYEB_SERVICE_ID) | |
| for var in "${REQUIRED[@]}"; do | |
| if [ -z "${!var}" ]; then | |
| echo "❌ Error: $var environment variable is missing, please check repository Secrets." | |
| exit 1 | |
| fi | |
| done | |
| echo "Calling Koyeb API to send redeploy request..." | |
| RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" -X POST "https://app.koyeb.com/v1/services/$KOYEB_SERVICE_ID/redeploy" \ | |
| -H "Authorization: Bearer $KOYEB_API_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{}") | |
| HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | tail -n 1 | awk -F":" '{print $2}') | |
| if [ "$HTTP_STATUS" -eq 200 ] || [ "$HTTP_STATUS" -eq 204 ] || [ "$HTTP_STATUS" -eq 201 ]; then | |
| echo "✅ Successfully triggered Koyeb service restart!" | |
| else | |
| echo "❌ Failed to trigger Koyeb service restart! (HTTP Status: $HTTP_STATUS)" | |
| echo "Response: $RESPONSE" | |
| exit 1 | |
| fi |