Auto-bump build number on each compile; ship versioned Windows artifacts. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
2.5 KiB
PowerShell
60 lines
2.5 KiB
PowerShell
# Increment BuildNumber in update.go and sync version artifacts (no Python required).
|
|
$ErrorActionPreference = "Stop"
|
|
$Root = Split-Path -Parent $PSScriptRoot
|
|
|
|
$updateGo = Join-Path $Root "internal\update\update.go"
|
|
$text = [IO.File]::ReadAllText($updateGo)
|
|
$m = [regex]::Match($text, 'const BuildNumber\s*=\s*(\d+)')
|
|
if (-not $m.Success) { throw "cannot find BuildNumber in update.go" }
|
|
$old = [int]$m.Groups[1].Value
|
|
$new = $old + 1
|
|
$text2 = [regex]::Replace($text, 'const BuildNumber\s*=\s*\d+', "const BuildNumber = $new", 1)
|
|
[IO.File]::WriteAllText($updateGo, $text2)
|
|
Write-Host "BuildNumber: $old -> $new"
|
|
|
|
$verM = [regex]::Match($text2, 'CurrentVersion\s*=\s*"([^"]+)"')
|
|
if (-not $verM.Success) { throw "cannot find CurrentVersion" }
|
|
$ver = $verM.Groups[1].Value
|
|
$parts = @($ver.Split('.') | ForEach-Object { [int]$_ })
|
|
while ($parts.Count -lt 3) { $parts += 0 }
|
|
$major, $minor, $patch = $parts[0], $parts[1], $parts[2]
|
|
$full = "$ver.$new"
|
|
$display = "$ver+$new"
|
|
$versionCode = $major * 1000000 + $minor * 10000 + $patch * 100 + $new
|
|
|
|
$viPath = Join-Path $Root "versioninfo.json"
|
|
$vi = [IO.File]::ReadAllText($viPath)
|
|
$vi = [regex]::Replace($vi, '("FileVersion"\s*:\s*\{\s*"Major"\s*:\s*)\d+', "`${1}$major", 1)
|
|
$vi = [regex]::Replace($vi, '("Minor"\s*:\s*)\d+(\s*,\s*"Patch")', "`${1}$minor`${2}", 1)
|
|
$vi = [regex]::Replace($vi, '("Patch"\s*:\s*)\d+(\s*,\s*"Build")', "`${1}$patch`${2}", 1)
|
|
$vi = [regex]::Replace($vi, '("Build"\s*:\s*)\d+', "`${1}$new", 2)
|
|
$vi = [regex]::Replace($vi, '("FileVersion"\s*:\s*")\d+\.\d+\.\d+\.\d+(")', "`${1}$full`${2}")
|
|
$vi = [regex]::Replace($vi, '("ProductVersion"\s*:\s*")\d+\.\d+\.\d+\.\d+(")', "`${1}$full`${2}")
|
|
[IO.File]::WriteAllText($viPath, $vi)
|
|
Write-Host "updated versioninfo.json -> $full"
|
|
|
|
$batPath = Join-Path $Root "build-macos.bat"
|
|
$bat = [IO.File]::ReadAllText($batPath)
|
|
$bat2 = [regex]::Replace(
|
|
$bat,
|
|
'-version\s+\d+\.\d+\.\d+\s+-build\s+\d+\.\d+\.\d+\.\d+',
|
|
"-version $ver -build $full"
|
|
)
|
|
if ($bat2 -ne $bat) {
|
|
[IO.File]::WriteAllText($batPath, $bat2)
|
|
Write-Host "updated build-macos.bat -> $ver $full"
|
|
}
|
|
|
|
$gradlePath = Join-Path $Root "android\app\build.gradle.kts"
|
|
if (Test-Path $gradlePath) {
|
|
$g = [IO.File]::ReadAllText($gradlePath)
|
|
$g2 = [regex]::Replace($g, 'versionCode\s*=\s*[\d_]+', "versionCode = $versionCode")
|
|
$g2 = [regex]::Replace($g2, 'versionName\s*=\s*"[^"]+"', "versionName = `"$display`"")
|
|
if ($g2 -ne $g) {
|
|
[IO.File]::WriteAllText($gradlePath, $g2)
|
|
Write-Host "updated android gradle -> $display $versionCode"
|
|
}
|
|
}
|
|
|
|
Write-Host "bump complete: $full"
|