Add detailed error handling to DO deploy step
- Capture HTTP status codes from both API calls - List all apps found (for debugging name mismatch) - Print full JSON on failure instead of silent exit 1 - Use set -euo pipefail for strict error handling
This commit is contained in:
@@ -31,27 +31,61 @@ jobs:
|
|||||||
- name: Deploy to DigitalOcean App Platform
|
- name: Deploy to DigitalOcean App Platform
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
run: |
|
run: |
|
||||||
# Find app ID by name
|
set -euo pipefail
|
||||||
APP_ID=$(curl -s -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
TOKEN="$DIGITALOCEAN_TOKEN"
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
"https://api.digitalocean.com/v2/apps?page=1&page_limit=20" | \
|
|
||||||
jq -r '.apps[] | select(.spec.name == "simcoetradesjournal") | .id')
|
|
||||||
|
|
||||||
if [ -z "$APP_ID" ] || [ "$APP_ID" = "null" ]; then
|
# List all apps with full details
|
||||||
echo "ERROR: Could not find DO app 'simcoetradesjournal'"
|
echo "=== Fetching apps from DO API ==="
|
||||||
|
APPS_JSON=$(curl -s -w "\n%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"https://api.digitalocean.com/v2/apps?page=1&page_limit=20")
|
||||||
|
|
||||||
|
HTTP_CODE=$(echo "$APPS_JSON" | tail -1)
|
||||||
|
BODY=$(echo "$APPS_JSON" | sed '$d')
|
||||||
|
|
||||||
|
echo "HTTP Status: $HTTP_CODE"
|
||||||
|
if [ "$HTTP_CODE" != "200" ]; then
|
||||||
|
echo "ERROR: DO API returned $HTTP_CODE"
|
||||||
|
echo "Response: $BODY"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Found DO app ID: $APP_ID"
|
# Show all app names for debugging
|
||||||
|
echo "=== All apps found ==="
|
||||||
|
echo "$BODY" | jq -r '.apps[] | " - \(.spec.name) (id: \(.id))"'
|
||||||
|
|
||||||
|
# Find app ID — try exact name match first, then partial
|
||||||
|
APP_ID=$(echo "$BODY" | jq -r '.apps[] | select(.spec.name == "simcoetradesjournal") | .id' | head -1)
|
||||||
|
|
||||||
|
if [ -z "$APP_ID" ] || [ "$APP_ID" = "null" ]; then
|
||||||
|
echo "ERROR: Could not find DO app named 'simcoetradesjournal'"
|
||||||
|
echo "Full response:"
|
||||||
|
echo "$BODY" | jq .
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== Found DO app ID: $APP_ID ==="
|
||||||
|
|
||||||
# Trigger deployment
|
# Trigger deployment
|
||||||
DEPLOY_RESPONSE=$(curl -s -X POST \
|
echo "=== Triggering deployment ==="
|
||||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
DEPLOY_JSON=$(curl -s -w "\n%{http_code}" -X POST \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"https://api.digitalocean.com/v2/apps/$APP_ID/deploy")
|
"https://api.digitalocean.com/v2/apps/$APP_ID/deploy")
|
||||||
|
|
||||||
DEPLOY_ID=$(echo "$DEPLOY_RESPONSE" | jq -r '.deployments[0].id')
|
DEPLOY_HTTP=$(echo "$DEPLOY_JSON" | tail -1)
|
||||||
echo "Deployment triggered: $DEPLOY_ID"
|
DEPLOY_BODY=$(echo "$DEPLOY_JSON" | sed '$d')
|
||||||
echo "Response: $DEPLOY_RESPONSE"
|
|
||||||
|
echo "Deploy HTTP Status: $DEPLOY_HTTP"
|
||||||
|
if [ "$DEPLOY_HTTP" != "200" ]; then
|
||||||
|
echo "ERROR: Deploy API returned $DEPLOY_HTTP"
|
||||||
|
echo "Response: $DEPLOY_BODY"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEPLOY_ID=$(echo "$DEPLOY_BODY" | jq -r '.deployments[0].id // empty')
|
||||||
|
echo "=== Deployment triggered successfully ==="
|
||||||
|
echo "Deploy ID: $DEPLOY_ID"
|
||||||
env:
|
env:
|
||||||
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
|
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
|
||||||
|
|||||||
Reference in New Issue
Block a user