Private/Get-SemanticVersion.ps1
|
<# .SYNOPSIS Parses a semantic version string. .DESCRIPTION Parses a version string (with or without 'v' prefix) into components. .PARAMETER Version Version string to parse (e.g., "v1.2.3" or "1.2.3-alpha.1") .OUTPUTS [PSCustomObject] with Major, Minor, Patch, PreRelease, Build, FullVersion, HasVPrefix properties. #> function Get-SemanticVersion { [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter(Mandatory)] [string]$Version ) $versionString = $Version -replace '^v', '' if ($versionString -match '^(\d+)\.(\d+)\.(\d+)(-([a-zA-Z0-9.]+))?(\+([a-zA-Z0-9.]+))?$') { return [PSCustomObject]@{ Major = [int]$Matches[1] Minor = [int]$Matches[2] Patch = [int]$Matches[3] PreRelease = $Matches[5] Build = $Matches[7] FullVersion = $Version HasVPrefix = $Version.StartsWith('v') } } else { throw "Invalid semantic version format: '$Version'. Expected format: [v]Major.Minor.Patch[-PreRelease][+Build]" } } |