Implementado o versionamento de versão da extensão

This commit is contained in:
Paulo Porto
2026-04-30 12:56:22 -03:00
parent 45cfceff0e
commit ca839345bc
4 changed files with 102 additions and 2 deletions

View File

@@ -0,0 +1,65 @@
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"