generated from Stravaig-Projects/stravaig-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bump-Version.ps1
53 lines (44 loc) · 1.06 KB
/
Bump-Version.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
[CmdletBinding()]
param (
[Switch]
$BumpMajor,
[Switch]
$BumpMinor,
[Switch]
$BumpPatch
)
$VersionFile = "$PSScriptRoot/version.txt";
$currentVersion = Get-Content $VersionFile -ErrorAction Stop
if ($null -eq $currentVersion)
{
Write-Error "The $VersionFile file is empty"
Exit 1
}
if ($currentVersion.GetType().BaseType.Name -eq "Array")
{
$currentVersion = $currentVersion[0]
Write-Warning "$VersionFile contains more than one line of text. Using the first line."
}
if ($currentVersion -notmatch "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$")
{
Write-Error "The contents of $VersionFile (`"$nextVersion`") not recognised as a valid version number."
Exit 2
}
$parts = $currentVersion.Split('.');
[int]$major = $parts[0]
[int]$minor = $parts[1]
[int]$patch = $parts[2]
if ($BumpMajor)
{
$major += 1;
}
if ($BumpMinor)
{
$minor += 1;
}
if ($BumpPatch)
{
$patch += 1;
}
$newVersion = "$major.$minor.$patch";
Set-Content $VersionFile $newVersion -Encoding UTF8 -Force