Skip to content

Commit e38fa5a

Browse files
committed
ci: validate Cargo.toml version match count in SetVersion.ps1
1 parent f55b78a commit e38fa5a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cicd/SetVersion.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ $newVersion = [regex]::Replace($content, $pattern, {
3434
# Only replaces `version = "..."` within the [package] section, before the next section header.
3535
$cargoTomlPath = Join-Path $PSScriptRoot ".." "wimygit-tauri" "src-tauri" "Cargo.toml"
3636
$cargoToml = Get-Content $cargoTomlPath -Raw
37-
$cargoToml = $cargoToml -replace '(?ms)(\[package\].*?)^version = "[^"]*"', "`$1version = `"$newVersion`""
37+
$pattern = '(?ms)(\[package\].*?)^version = "[^"]*"'
38+
$matchCount = [regex]::Matches($cargoToml, $pattern).Count
39+
if ($matchCount -ne 1) {
40+
throw "Cargo.toml: expected exactly 1 version match in [package] section, but found $matchCount"
41+
}
42+
$cargoToml = $cargoToml -replace $pattern, "`$1version = `"$newVersion`""
3843
Set-Content $cargoTomlPath $cargoToml -NoNewline -Encoding UTF8
3944

4045
Set-Location (Join-Path $PSScriptRoot ".." "wimygit-tauri")

0 commit comments

Comments
 (0)