Skip to content

Commit fa3f3ad

Browse files
committed
✨ 优化版本更新逻辑,仅更新 [package] 部分的 version
1 parent bf870a0 commit fa3f3ad

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

scripts/release.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ if ($currentBranch -ne "main" -and $currentBranch -ne "master" -and -not $DryRun
6363
Write-Info "📝 更新 Cargo.toml 版本到 $Version"
6464
if (-not $DryRun) {
6565
$cargoContent = Get-Content "Cargo.toml" -Raw
66-
$cargoContent = $cargoContent -replace 'version = "[^"]*"', "version = `"$Version`""
66+
# 只更新 [package] 部分的 version,使用更精确的正则表达式
67+
$cargoContent = $cargoContent -replace '(\[package\][\s\S]*?)version\s*=\s*"[^"]*"', "`$1version = `"$Version`""
6768
Set-Content "Cargo.toml" -Value $cargoContent -NoNewline
6869
}
6970

scripts/release.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ fi
8181
# 更新 Cargo.toml 中的版本
8282
log_info "📝 更新 Cargo.toml 版本到 $VERSION"
8383
if [ "$DRY_RUN" = false ]; then
84-
# 使用 sed 更新版本
84+
# 使用 sed 更新版本,只更新 [package] 部分的第一个 version
8585
if [[ "$OSTYPE" == "darwin"* ]]; then
8686
# macOS
87-
sed -i '' "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" Cargo.toml
87+
sed -i '' '/^\[package\]/,/^\[/ { /^version = / { s/^version = "[^"]*"/version = "'"$VERSION"'"/; } }' Cargo.toml
8888
else
8989
# Linux
90-
sed -i "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" Cargo.toml
90+
sed -i '/^\[package\]/,/^\[/ { /^version = / { s/^version = "[^"]*"/version = "'"$VERSION"'"/; } }' Cargo.toml
9191
fi
9292
fi
9393

0 commit comments

Comments
 (0)