-
Notifications
You must be signed in to change notification settings - Fork 67
40 lines (37 loc) · 1.55 KB
/
Copy pathkoyeb.yml
File metadata and controls
40 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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