Files
code.coverage.extractor/build/GetBuildVersion.psm1
T
2024-01-09 21:27:35 +03:00

34 lines
957 B
PowerShell

Function GetBuildVersion {
Param (
[string]$VersionString
)
# Process through regex
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null
if ($matches -eq $null) {
return "1.0.0-build"
}
# Extract the build metadata
$BuildRevision = [uint64]$matches['build']
# Extract the pre-release tag
$PreReleaseTag = [string]$matches['pre']
# Extract the patch
$Patch = [uint64]$matches['patch']
# Extract the minor
$Minor = [uint64]$matches['minor']
# Extract the major
$Major = [uint64]$matches['major']
$Version = [string]$Major + '.' + [string]$Minor + '.' + [string]$Patch;
if ($PreReleaseTag -ne [string]::Empty) {
$Version = $Version + '-' + $PreReleaseTag
}
if ($BuildRevision -ne 0) {
$Version = $Version + '.' + [string]$BuildRevision
}
return $Version
}