From 75e1e8dd7968beb437b67642bce4e5324f3233ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 14 Nov 2025 23:00:20 +0800 Subject: [PATCH] Improve error handling in release workflow Enhances the OpenRouter API call step by adding error handling for both curl and jq failures. If the API call or response parsing fails, the workflow now falls back to using a default release note template. --- .github/workflows/release.yml | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 39af7f6e..0e20f71e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -232,25 +232,32 @@ jobs: echo "$BODY" | jq . # 调用 OpenRouter - RESPONSE=$(curl -s -X POST "$OPENROUTER_API_URL" \ + if RESPONSE=$(curl -s -X POST "$OPENROUTER_API_URL" \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ - -d "$BODY") - echo "=== raw response ===" - echo "$RESPONSE" - echo "=== OpenRouter raw response ===" - echo "$RESPONSE" | jq . + -d "$BODY"); then + echo "=== raw response ===" + echo "$RESPONSE" + echo "=== OpenRouter raw response ===" + if echo "$RESPONSE" | jq . >/dev/null 2>&1; then + echo "$RESPONSE" | jq . + else + echo "jq failed to parse response" + fi - # 提取生成内容 - RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // .choices[0].text // ""') + # 提取生成内容 + RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // .choices[0].text // ""' 2>/dev/null || echo "") - if [ -z "$RELEASE_BODY" ]; then - echo "❌ OpenRouter failed to generate release note, terminating workflow." - exit 1 + if [ -z "$RELEASE_BODY" ]; then + echo "❌ OpenRouter failed to generate release note, using default.md" + cp .github/prompt/default.md CHANGELOG.md + else + echo -e "$RELEASE_BODY" > CHANGELOG.md + fi + else + echo "❌ Curl failed, using default.md" + cp .github/prompt/default.md CHANGELOG.md fi - - # 输出到 CHANGELOG.md - echo -e "$RELEASE_BODY" > CHANGELOG.md echo "=== generated release note ===" cat CHANGELOG.md