functions/GetSemVerIncrement.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
function GetSemVerIncrement
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [System.Management.Automation.SemanticVersion]
        $FromVersion,

        [Parameter(Mandatory=$true)]
        [system.Management.Automation.SemanticVersion]
        $ToVersion
    )

    $ErrorActionPreference = 'Stop'

    if ($FromVersion -eq $ToVersion) {
        throw "The versions are the same"
    }

    $upgradeType = 'patch'

    if ($ToVersion.Major -gt $FromVersion.Major) {
        $upgradeType = 'major'
    }
    elseif ($ToVersion.Minor -gt $FromVersion.Minor) {
        $upgradeType = 'minor'
    }

    Write-Verbose ('SemVerIncrement: {0}' -f $upgradeType)
    $upgradeType
}