From 5b6e23c49f050f982a8f8cb637c686683ef353b0 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 29 Mar 2026 21:30:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20E2E=20Health=20Check=20=E8=A8=BA?= =?UTF-8?q?=E6=96=B7=E5=BC=B7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2026-03-29 Claude Code: - 清除舊快取檔案避免讀到 stale response - 增加 TCP 連接測試 (/dev/tcp) - curl verbose 模式輸出診斷資訊 - 簡化 HTTP code 取得方式 - 增加 nc 直接測試作為備用 Co-Authored-By: Claude Opus 4.5 --- .github/workflows/daily-e2e-health.yaml | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/daily-e2e-health.yaml b/.github/workflows/daily-e2e-health.yaml index 0159c0fe..af92905f 100644 --- a/.github/workflows/daily-e2e-health.yaml +++ b/.github/workflows/daily-e2e-health.yaml @@ -99,15 +99,28 @@ jobs: echo "🔗 檢查 API 健康狀態..." echo "📍 Runner: $(hostname)" echo "🌐 Target: $API_URL" + echo "📂 Working Dir: $(pwd)" + + # 2026-03-29 Claude Code: 清除舊檔案避免讀到上次快取 + rm -f /tmp/health_response.txt /tmp/fallback_response.txt 2>/dev/null || true # 診斷網路連通性 VIP_IP=$(echo "$API_URL" | sed -E 's|https?://([^:]+).*|\1|') echo "🔍 Ping VIP ($VIP_IP)..." ping -c 2 "$VIP_IP" || echo "⚠️ Ping failed (may be blocked)" + # 2026-03-29 Claude Code: 增加 TCP 連接測試 + echo "🔌 TCP 連接測試 ($VIP_IP:32334)..." + timeout 5 bash -c "cat < /dev/null > /dev/tcp/$VIP_IP/32334" && echo "✅ TCP 連接成功" || echo "⚠️ TCP 連接失敗" + # 嘗試連線 (正確路徑: /api/v1/health) - echo "🔗 Curl health endpoint..." - HTTP_CODE=$(curl -s -o /tmp/health_response.txt -w "%{http_code}" --connect-timeout 15 "$API_URL/api/v1/health" || echo "000") + echo "🔗 Curl health endpoint (verbose)..." + # 2026-03-29 Claude Code: 改用 verbose 模式輸出診斷資訊 + curl -v --connect-timeout 15 "$API_URL/api/v1/health" -o /tmp/health_response.txt 2>&1 | head -30 || true + + # 2026-03-29 Claude Code: 重新取得 HTTP code (簡化) + HTTP_CODE=$(curl -s -w "%{http_code}" -o /dev/null --connect-timeout 15 "$API_URL/api/v1/health" 2>/dev/null) + echo "📊 HTTP Code: [$HTTP_CODE]" if [ "$HTTP_CODE" = "200" ]; then echo "✅ API 可用: $API_URL (HTTP $HTTP_CODE)" @@ -115,18 +128,22 @@ jobs: echo "working_api_url=$API_URL" >> $GITHUB_OUTPUT else echo "❌ API 無法連線: $API_URL (HTTP $HTTP_CODE)" - echo "📋 Response:" + echo "📋 Response (如有):" cat /tmp/health_response.txt 2>/dev/null || echo "(empty)" + # 2026-03-29 Claude Code: 使用 nc 直接測試 + echo "🔧 使用 nc 直接測試..." + echo -e "GET /api/v1/health HTTP/1.1\r\nHost: $VIP_IP:32334\r\n\r\n" | nc -w5 $VIP_IP 32334 | head -5 || echo "nc 測試失敗" + # 嘗試備用端點 (node 121 直連) FALLBACK_URL="http://192.168.0.121:32334" echo "🔄 嘗試備用端點: $FALLBACK_URL" - FALLBACK_CODE=$(curl -s -o /tmp/fallback_response.txt -w "%{http_code}" --connect-timeout 10 "$FALLBACK_URL/api/v1/health" || echo "000") + FALLBACK_CODE=$(curl -s -w "%{http_code}" -o /dev/null --connect-timeout 10 "$FALLBACK_URL/api/v1/health" 2>/dev/null) echo " 備用結果: HTTP $FALLBACK_CODE" if [ "$FALLBACK_CODE" = "200" ]; then echo "✅ 備用端點可用,VIP 可能有問題" - cat /tmp/fallback_response.txt + curl -s "$FALLBACK_URL/api/v1/health" echo "working_api_url=$FALLBACK_URL" >> $GITHUB_OUTPUT exit 0 # 備用成功,不算失敗 fi