-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathGetBuildVersion.psm1
42 lines (35 loc) · 1.35 KB
/
GetBuildVersion.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Function GetBuildVersion {
Param (
[string]$BaseVersion = "1.0.0",
[string]$VersionString,
[string]$BuildNumber
)
# If it is a PR, then grab the PR number and append to the base version.
if ($VersionString -match "refs/pull/(?<pr>\d+)/merge") {
return "$($BaseVersion)-pr.$($matches['pr'])"
}
# Process through regex
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null
# If the version string is the main branch, then we just append the build number
if ($VersionString -eq "refs/heads/main" -or $matches -eq $null) {
return "$($BaseVersion)-build.$($BuildNumber)"
}
# 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
}