-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateTaskVersion.ps1
32 lines (25 loc) · 1016 Bytes
/
UpdateTaskVersion.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
Param()
$branchName = $env:BUILD_SOURCEBRANCHNAME
$taskJsonPath = '.\DedupeGitReposV0\task.json'
function ConvertTo-SemVer($version){
$version -match "^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>[0-9A-Za-z\-\.]+))?$" | Out-Null
$major = [int]$matches['major']
$minor = [int]$matches['minor']
$patch = [int]$matches['patch']
if($null -eq $matches['pre']){$pre = @()}
else{$pre = $matches['pre'].Split(".")}
New-Object PSObject -Property @{
Major = $major
Minor = $minor
Patch = $patch
Pre = $pre
VersionString = $version
}
}
$taskJson = Get-Content $taskJsonPath | ConvertFrom-Json
$semVer = ConvertTo-SemVer $branchName.TrimStart('v')
$taskJson.version.Major = $semVer.Major
$taskJson.version.Minor = $semVer.Minor
$taskJson.version.Patch = $semVer.Patch
$taskJson.preview = $semVer.Pre.Length -gt 0
$taskJson | ConvertTo-Json -Depth 5 | Set-Content $taskJsonPath