forked from wasteam/waslibs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Version-ValidateAndUpdate.ps1
82 lines (70 loc) · 2.64 KB
/
Version-ValidateAndUpdate.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$MayorVersion,
[Parameter(Mandatory=$True,Position=2)]
[string]$MinorVersion,
[Parameter(Mandatory=$False,Position=3)]
[String]$Patch,
[Parameter(Mandatory=$False,Position=4)]
[string]$Semantic = "",
[Parameter(Mandatory=$False,Position=5)]
[string]$Revision = "",
[Parameter(Mandatory=$False, Position=6)]
[string]$TfsBuildNumber="" #Must match the pattern buildName_YYYYMMDD.r
)
if($error){
$error.Clear()
}
if($Patch -ne "" -and $TfsBuildNumber -ne ""){
throw "Is not allowed to specify the parameter TfsBuildNumber and Patch at the same time"
}
if($Patch -eq "" -and $TfsBuildNumber -eq ""){
throw "You must specify the parameter TfsBuildNumber or Patch"
}
if($TfsBuildNumber -ne ""){
if($Revision -ne "" -or $Semantic -ne "") {
throw "Semantic and/or Revision can't be specified if you set the BuildName parameter"
}
else{
Write-Host "Infering version from BuildName $TfsBuildNumber"
$TfsBuildNumberRegEx = "_(\d\d\d\d\d\d\d\d)\.(\d+)"
if($TfsBuildNumber -match $TfsBuildNumberRegEx){
$buildDate = [DateTime]::ParseExact($matches[1], "yyyyMMdd", $null)
$BuildMonthDay = $buildDate.DayOfYear.ToString("#000");
$BuildRevision = ([int]$matches[2]).ToString("#00");
Write-Host "Build Month and Day: $BuildMonthDay"
Write-Host "Build Revision: $BuildRevision"
$Revision = $BuildRevision
$NewVersion = $MayorVersion + "." + $MinorVersion + "." + $BuildMonthDay + $Revision
$Semantic = "" #Ensure No Semantic Version for CI Builds
}
else{
throw "Build format does not match the expected pattern (buildName_YYYYMMDD.r)"
}
}
}
else{
$NewVersion = $MayorVersion + "." + $MinorVersion + "." + $Patch
}
if(!$error -and $NewVersion -and $NewVersion -ne ""){
$PackageVersion = $NewVersion
if($Semantic -ne "") {
$PackageVersion = $PackageVersion + "-" + $Semantic + $Revision
}
$PackageVersionTag = "$PackageVersion.r$Revision"
Write-Host "New Version: $NewVersion"
Write-Host "Revision: $Revision"
Write-Host "Package Version: $PackageVersion"
Write-Host "Package Version: $PackageVersion"
Write-Host "Invoking UpdateVersionFiles.ps1..."
Invoke-Command -ScriptBlock { .\UpdateVersionFiles.ps1 $NewVersion $Semantic $Revision }
Write-Host "UpdateVersionFiles.ps1 Finished."
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$PackageVersion")
Write-Host "Environment Variable NugetPackageVersion set."
Write-Host ("##vso[task.setvariable variable=PackageVersionTag;]$PackageVersionTag")
Write-Host "Environment Variable PackageVersionTag set."
}
else{
throw "New version for packages can't be determined."
}