-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResolve-NextVersion.ps1
59 lines (51 loc) · 1.63 KB
/
Resolve-NextVersion.ps1
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function Resolve-NextVersion {
<#
.EXAMPLE
Resolve-NextVersion '0.1.0'
0.1.1
.EXAMPLE
Resolve-NextVersion '0.1.0' -NewMajorVersion
1.0.0
.EXAMPLE
Resolve-NextVersion '0.1.0' -NewMinorVersion
0.2.0
#>
param(
# Baseline Value
[Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)]
[AllowNull()]
[Alias('Version','FileVersion')]
[version]
$CurrentVersion,
# Value to use for new files/packages
[Parameter()]
[version]
$InitialVersion = '0.1.0',
# Setting this will increment major and zero the rest
[Parameter()]
[switch]
$NewMajorVersion,
# Setting this will increment minor and zero the build
[Parameter()]
[switch]
$NewMinorVersion
)
$v = $CurrentVersion # abbrieviation only
$strVersion = "$($v.Major).$($v.Minor).$($v.Build)"
# Calculate Next Version
if ($strVersion -eq '..') {
$InitialVersion
} elseif ($NewMajorVersion.IsPresent) {
$newMajor = ([version]$strVersion).Major + 1
"$($newMajor).0.0" -as [version]
} elseif ($NewMinorVersion.IsPresent) {
$oldMajor = ([version]$strVersion).Major
$newMinor = ([version]$strVersion).Minor + 1
"$($oldMajor).$($newMinor).0" -as [version]
} else {
$oldMajor = ([version]$strVersion).Major
$oldMinor = ([version]$strVersion).Minor
$newBuild = ([version]$strVersion).Build + 1
"$($oldMajor).$($oldMinor).$($newBuild)" -as [version]
}
}#END: function Resolve-NextVersion