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:
Your Name
2026-08-01 06:17:04 -04:00
parent 87de514123
commit 4348a51a42
+47 -13
View File
@@ -31,27 +31,61 @@ jobs:
- name: Deploy to DigitalOcean App Platform
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
# Find app ID by name
APP_ID=$(curl -s -H "Authorization: Bearer $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')
set -euo pipefail
TOKEN="$DIGITALOCEAN_TOKEN"
if [ -z "$APP_ID" ] || [ "$APP_ID" = "null" ]; then
echo "ERROR: Could not find DO app 'simcoetradesjournal'"
# List all apps with full details
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
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
DEPLOY_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
echo "=== Triggering deployment ==="
DEPLOY_JSON=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
"https://api.digitalocean.com/v2/apps/$APP_ID/deploy")
DEPLOY_ID=$(echo "$DEPLOY_RESPONSE" | jq -r '.deployments[0].id')
echo "Deployment triggered: $DEPLOY_ID"
echo "Response: $DEPLOY_RESPONSE"
DEPLOY_HTTP=$(echo "$DEPLOY_JSON" | tail -1)
DEPLOY_BODY=$(echo "$DEPLOY_JSON" | sed '$d')
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:
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}