diff --git a/rel.sh b/rel.sh index 24c19d7..17b4a26 100755 --- a/rel.sh +++ b/rel.sh @@ -133,8 +133,8 @@ resp_body=$(echo "$response_full" | sed '$d') if [ "$http_code" -eq 201 ]; then echo "✅ Release 创建成功: $VERSION" -else - if [ "$http_code" -eq 409 ]; then + else + if [ "$http_code" -eq 409 ]; then echo "⚠️ 创建 Release 返回 409 Conflict,尝试删除远程冲突的 Release 并重试..." # 再次查询 Release id check_response=$(curl -s -w "\n%{http_code}" \ @@ -172,8 +172,29 @@ else echo "❌ 查询冲突 Release 失败 (HTTP $check_http_code),响应: $check_body" fi else - echo "❌ Release 创建失败,HTTP $http_code" - echo "响应: $resp_body" + # 如果是 500 并且包含 collation/utf8 相关错误,回退到英文 body 重试 + if [ "$http_code" -eq 500 ] || echo "$resp_body" | grep -qi "collation\|utf8\|Conversion from collation"; then + echo "⚠️ 检测到字符集/编码错误 (HTTP $http_code),尝试回退到英文说明并重试..." + ENGLISH_BODY="## Release Notes\n\nThis is release $VERSION: $RELEASE_TITLE\n\nFor detailed Chinese release notes, please see release.md in the repository.\n\nQuick start:\n\n\`\`\`bash\ngit pull origin main\ncd web && npm install\nnpm run dev\n\`\`\`" + JSON_PAYLOAD_EN=$(jq -n -c --arg version "$VERSION" --arg name "$VERSION" --arg body "$ENGLISH_BODY" '{tag_name: $version, name: $name, body: $body, draft: false, prerelease: false}') + echo "🔄 正在创建 Release(英文回退,重试)..." + en_resp=$(curl -s -w "\n%{http_code}" \ + -X POST "$GITEA_URL/api/v1/repos/$GITEA_REPO/releases" \ + -H "Content-Type: application/json" \ + -H "Authorization: token $GITEA_TOKEN" \ + -d "$JSON_PAYLOAD_EN") + en_code=$(echo "$en_resp" | tail -n 1) + en_body=$(echo "$en_resp" | sed '$d') + if [ "$en_code" -eq 201 ]; then + echo "✅ Release 创建成功 (英文回退): $VERSION" + else + echo "❌ 英文回退重试失败 (HTTP $en_code)" + echo "响应: $en_body" + fi + else + echo "❌ Release 创建失败,HTTP $http_code" + echo "响应: $resp_body" + fi fi fi