File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed
Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ if ($currentBranch -ne "main" -and $currentBranch -ne "master" -and -not $DryRun
6363Write-Info " 📝 更新 Cargo.toml 版本到 $Version "
6464if (-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
Original file line number Diff line number Diff line change 8181# 更新 Cargo.toml 中的版本
8282log_info " 📝 更新 Cargo.toml 版本到 $VERSION "
8383if [ " $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
9292fi
9393
You can’t perform that action at this time.
0 commit comments