update at 2025-10-15 15:36:54

This commit is contained in:
douboer
2025-10-15 15:36:54 +08:00
parent d4429a8525
commit 4671f3f6ee
3 changed files with 131 additions and 244 deletions

View File

@@ -64,17 +64,40 @@ if [ ! -f release.md ]; then
exit 1
fi
VERSION=$(grep "^## v" release.md | tail -n 1 | sed 's/^## //')
TAG_MESSAGE=$(awk "/^## $VERSION/{flag=1;next}/^## v/{flag=0}flag" release.md)
# 提取最后一个版本号(去掉 ## 和空格)
VERSION=$(grep "^## v" release.md | tail -n 1 | sed 's/^## *//')
if [ -z "$VERSION" ]; then
echo "❌ release.md 中未找到版本号"
exit 1
fi
# 提取该版本块的内容(从版本标题下一行到下一个版本或文件结尾)
TAG_MESSAGE=$(awk "
/^## $VERSION\$/ { flag=1; next }
/^## v[0-9]/ && flag { exit }
flag { print }
" release.md)
# 提取标题(第一个非空的实质性内容行,通常是 "发布时间:" 后的第一行)
# 跳过空行和"发布时间:"行,取第一个 ### 标题
RELEASE_TITLE=$(echo "$TAG_MESSAGE" | grep -m 1 "^###" | sed 's/^### *//' | sed 's/^[🎯✨🔧🐛📦]* *//')
# 如果没有找到 ### 标题,尝试找第一个非空行
if [ -z "$RELEASE_TITLE" ]; then
RELEASE_TITLE=$(echo "$TAG_MESSAGE" | grep -v "^$" | grep -v "^发布时间:" | head -n 1)
fi
# 如果还是没有,使用版本号作为标题
if [ -z "$RELEASE_TITLE" ]; then
RELEASE_TITLE="Release $VERSION"
fi
echo "📝 版本号: $VERSION"
echo "说明:"
echo "$TAG_MESSAGE"
echo "📌 标题: $RELEASE_TITLE"
echo "📄 内容预览:"
echo "$TAG_MESSAGE" | head -n 10
echo "..."
# 5. 创建 tag如已存在则删除后重建
if git rev-parse "$VERSION" >/dev/null 2>&1; then
@@ -119,15 +142,49 @@ if [ -z "$GITEA_TOKEN" ]; then
exit 0
fi
# 使用 jq 生成正确的 JSON
# 7.1 检查远程是否已存在该版本的 Release如果存在则删除
echo "🔍 检查远程 Release 是否已存在..."
check_response=$(curl -s -w "\n%{http_code}" \
-X GET "$GITEA_URL/api/v1/repos/$GITEA_REPO/releases/tags/$VERSION" \
-H "Authorization: token $GITEA_TOKEN")
check_http_code=$(echo "$check_response" | tail -n 1)
check_body=$(echo "$check_response" | sed '$d')
if [ "$check_http_code" -eq 200 ]; then
# Release 已存在,获取 Release ID 并删除
release_id=$(echo "$check_body" | jq -r '.id')
echo "⚠️ 远程已存在 Release $VERSION (ID: $release_id),正在删除..."
delete_response=$(curl -s -w "\n%{http_code}" \
-X DELETE "$GITEA_URL/api/v1/repos/$GITEA_REPO/releases/$release_id" \
-H "Authorization: token $GITEA_TOKEN")
delete_http_code=$(echo "$delete_response" | tail -n 1)
if [ "$delete_http_code" -eq 204 ] || [ "$delete_http_code" -eq 200 ]; then
echo "✅ 已删除旧的 Release"
else
echo "⚠️ 删除 Release 失败 (HTTP $delete_http_code),但将继续创建新的..."
fi
elif [ "$check_http_code" -eq 404 ]; then
echo "✅ 远程不存在该 Release可以创建"
else
echo "⚠️ 检查 Release 状态失败 (HTTP $check_http_code),但将继续创建..."
fi
# 7.2 使用 jq 生成正确的 JSON
# 首先尝试使用原始内容(中文)
JSON_PAYLOAD=$(echo "$TAG_MESSAGE" | jq -R -s -c --arg version "$VERSION" '{
tag_name: $version,
name: $version,
body: .,
draft: false,
prerelease: false
}')
JSON_PAYLOAD=$(echo "$TAG_MESSAGE" | jq -R -s -c \
--arg version "$VERSION" \
--arg title "$VERSION - $RELEASE_TITLE" \
'{
tag_name: $version,
name: $title,
body: .,
draft: false,
prerelease: false
}')
echo "🔄 尝试创建 Release (使用中文内容)..."
response=$(curl -s -w "\n%{http_code}" \
@@ -147,11 +204,11 @@ elif [[ "$response_body" == *"Conversion from collation"* ]] || [[ "$response_bo
echo "⚠️ 检测到字符集问题,尝试使用英文版本..."
# 创建简化的英文版本
ENGLISH_BODY="## Release Notes\n\nThis is release $VERSION.\n\nFor detailed Chinese release notes, please see:\n- release.md in the repository\n- Or visit: $GITEA_URL/$GITEA_REPO/src/branch/main/release.md\n\n### Quick Start\n\n\`\`\`bash\ngit pull origin main\ncd web && npm install\nnpm run dev\n\`\`\`"
ENGLISH_BODY="## Release Notes\n\nThis is release $VERSION: $RELEASE_TITLE\n\nFor detailed Chinese release notes, please see:\n- release.md in the repository\n- Or visit: $GITEA_URL/$GITEA_REPO/src/branch/main/release.md\n\n### Quick 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 - Release" \
--arg name "$VERSION - $RELEASE_TITLE" \
--arg body "$ENGLISH_BODY" \
'{
tag_name: $version,