1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Verifies that Hematite's tracked release-version surfaces are in sync.
# Usage:
# pwsh ./scripts/verify-version-sync.ps1
# pwsh ./scripts/verify-version-sync.ps1 -Version X.Y.Z -PreviousVersion A.B.C
param(
[string]$Version,
[string]$PreviousVersion,
[switch]$RequireCargoLock
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
Set-Location $repoRoot
function Get-FileText([string]$Path) {
Get-Content -LiteralPath $Path -Raw
}
function Require-Match([string]$Path, [string]$Pattern, [string]$Description) {
$text = Get-FileText $Path
if ($text -notmatch $Pattern) {
throw "$Path is out of sync: expected $Description"
}
}
function Reject-Match([string]$Path, [string]$Pattern, [string]$Description) {
$text = Get-FileText $Path
if ($text -match $Pattern) {
throw "$Path still contains $Description"
}
}
if (-not $Version) {
$cargoToml = Get-FileText "Cargo.toml"
$versionMatch = [regex]::Match($cargoToml, '(?m)^version\s*=\s*"([^"]+)"')
if (-not $versionMatch.Success) {
throw "Could not determine package version from Cargo.toml."
}
$Version = $versionMatch.Groups[1].Value
}
else {
$cargoToml = Get-FileText "Cargo.toml"
}
$packageNameMatch = [regex]::Match($cargoToml, '(?m)^name\s*=\s*"([^"]+)"')
if (-not $packageNameMatch.Success) {
throw "Could not determine package name from Cargo.toml."
}
$packageName = $packageNameMatch.Groups[1].Value
$escapedVersion = [regex]::Escape($Version)
$escapedPackageName = [regex]::Escape($packageName)
$installerPattern = "(?m)^\s*#define AppVersion\s+`"$escapedVersion`"\r?$"
$readmeBadgePattern = [regex]::Escape("version-$Version")
$cargoLockPattern = "(?ms)\[\[package\]\]\s*name = `"$escapedPackageName`"\s*version = `"$escapedVersion`""
Require-Match "Cargo.toml" "(?m)^version\s*=\s*`"$escapedVersion`"\r?$" "Cargo.toml package version $Version"
Require-Match "installer\hematite.iss" $installerPattern "installer AppVersion $Version"
Require-Match "README.md" $readmeBadgePattern "README version badge for $Version"
if ($RequireCargoLock) {
Require-Match "Cargo.lock" $cargoLockPattern "Cargo.lock $packageName package version $Version"
}
if ($PreviousVersion) {
$escapedPrevious = [regex]::Escape($PreviousVersion)
Reject-Match "Cargo.toml" "\b$escapedPrevious\b" "previous version $PreviousVersion"
Reject-Match "README.md" "\b$escapedPrevious\b" "previous version $PreviousVersion"
Reject-Match "CLAUDE.md" "\b$escapedPrevious\b" "previous version $PreviousVersion"
Reject-Match "installer\hematite.iss" "\b$escapedPrevious\b" "previous version $PreviousVersion"
}
if ($RequireCargoLock) {
Write-Host "Version sync verified for $Version (including Cargo.lock)" -ForegroundColor Green
} else {
Write-Host "Version sync verified for $Version (static release surfaces)" -ForegroundColor Green
}