-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetTargetVersion.psm1
30 lines (30 loc) · 1016 Bytes
/
GetTargetVersion.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
function Get-TargetVersion {
param (
$NuGetVersioningDllPath
)
$lastTag = git describe --abbrev=0 --tags
if ([String]::IsNullOrWhiteSpace($lastTag)) {
$lastTag = 'v0.1.0'
$comitCount = git rev-list HEAD --count
}
else {
$comitCount = git rev-list "$lastTag..HEAD" --count
}
if ($lastTag.StartsWith('v') -or $lastTag.StartsWith('V')) {
$lastTag = $lastTag.SubString(1)
}
$null = [System.Reflection.Assembly]::LoadFrom($NuGetVersioningDllPath)
[ref]$lastVer = [NuGet.Versioning.SemanticVersion]::Parse('0.1.0')
if ([NuGet.Versioning.SemanticVersion]::TryParse($lastTag, $lastVer)) {
if ($lastVer.Value.IsPrerelease) {
$targetVer = "$lastVer-dev.$comitCount"
}
else {
$targetVer = "$($lastVer.Value.Major).$($lastVer.Value.Minor).$($lastVer.Value.Patch+1)-dev.$comitCount"
}
}
else {
$targetVer = "$lastVer-dev.$comitCount"
}
Write-Output $targetVer
}