diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ab1b358..0bcd249 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -116,3 +116,22 @@ jobs: --project ${{ env.PROJECT_ID }} \ --port 3000 \ --allow-unauthenticated + + - name: Health check (${{ matrix.region }}) + run: | + URL=$(gcloud run services describe ${{ env.SERVICE }} \ + --region ${{ matrix.region }} \ + --project ${{ env.PROJECT_ID }} \ + --format='value(status.url)') + echo "Checking $URL/api/health..." + for i in $(seq 1 10); do + STATUS=$(curl -sf "$URL/api/health" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status',''))" 2>/dev/null) + if [ "$STATUS" = "ok" ]; then + echo "Healthy (attempt $i)" + exit 0 + fi + echo " attempt $i: $STATUS" + sleep 5 + done + echo "Health check failed after 10 attempts" + exit 1 diff --git a/scripts/test-api-local.sh b/scripts/test-api-local.sh index 427742c..2a3ccb0 100755 --- a/scripts/test-api-local.sh +++ b/scripts/test-api-local.sh @@ -4,17 +4,14 @@ set -e PORT=3033 cleanup() { - echo "Cleaning up..." [ -n "$SERVER_PID" ] && kill $SERVER_PID 2>/dev/null - wait $SERVER_PID 2>/dev/null - echo "Done." + wait $SERVER_PID 2>/dev/null || true } trap cleanup EXIT echo "Starting API server on :$PORT..." API_PORT=$PORT node api.js 2>/dev/null & SERVER_PID=$! -SERVER_PID=$! echo "Waiting for server..." for i in $(seq 1 15); do