66 lines
1.6 KiB
PowerShell
66 lines
1.6 KiB
PowerShell
param(
|
|
[string]$Version
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = Split-Path -Parent $PSScriptRoot
|
|
$manifestPath = Join-Path $repoRoot "manifest.json"
|
|
|
|
function Test-ExtensionVersion {
|
|
param([string]$Value)
|
|
|
|
if ($Value -notmatch '^\d+\.\d+\.\d+$') {
|
|
throw "Invalid version '$Value'. Expected format N.N.N, for example 1.0.7."
|
|
}
|
|
|
|
foreach ($part in $Value.Split(".")) {
|
|
$number = [int64]$part
|
|
|
|
if ($number -lt 0 -or $number -gt 65535) {
|
|
throw "Invalid version '$Value'. Each part must be between 0 and 65535."
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!(Test-Path -LiteralPath $manifestPath)) {
|
|
throw "manifest.json not found at $manifestPath"
|
|
}
|
|
|
|
$rawManifest = Get-Content -LiteralPath $manifestPath -Raw
|
|
$manifest = $rawManifest | ConvertFrom-Json
|
|
$currentVersion = [string]$manifest.version
|
|
|
|
Test-ExtensionVersion -Value $currentVersion
|
|
|
|
if ($Version) {
|
|
$nextVersion = $Version.Trim()
|
|
Test-ExtensionVersion -Value $nextVersion
|
|
} else {
|
|
$parts = $currentVersion.Split(".")
|
|
$patch = [int64]$parts[2] + 1
|
|
|
|
if ($patch -gt 65535) {
|
|
throw "Cannot increment patch version beyond 65535."
|
|
}
|
|
|
|
$nextVersion = "$($parts[0]).$($parts[1]).$patch"
|
|
}
|
|
|
|
$versionPattern = '("version"\s*:\s*")([^"]+)(")'
|
|
$matches = [regex]::Matches($rawManifest, $versionPattern)
|
|
|
|
if ($matches.Count -ne 1) {
|
|
throw "Expected exactly one version field in manifest.json, found $($matches.Count)."
|
|
}
|
|
|
|
$updatedManifest = [regex]::Replace(
|
|
$rawManifest,
|
|
$versionPattern,
|
|
"`${1}$nextVersion`${3}",
|
|
1
|
|
)
|
|
|
|
Set-Content -LiteralPath $manifestPath -Value $updatedManifest -Encoding UTF8
|
|
Write-Output "Extension version updated: $currentVersion -> $nextVersion"
|