-
Notifications
You must be signed in to change notification settings - Fork 120
/
Set-MajorVersion.ps1
43 lines (33 loc) · 1.4 KB
/
Set-MajorVersion.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
[CmdletBinding()]
Param(
[int]$NewMajorVersion = 0
)
function Get-Version([string]$fullVersion)
{
$null = $fullVersion -match "(\d+)\.(\d+)(-.+)?"
return $matches[1], $matches[2], $matches[3]
}
$rootDir = [System.IO.Path]::GetFullPath("$PSScriptRoot\..")
$rootVersionJsonFile = Join-Path $rootDir "version.json"
# Update main version
$versionJson = Get-Content $rootVersionJsonFile -raw | ConvertFrom-Json
$currentVersion = $versionJson."version"
$currentMajor, $currentMinor, $currentSuffix = Get-Version $currentVersion
if ($NewMajorVersion -eq 0)
{
$NewMajorVersion = ($currentMajor -as [int]) + 1
}
$newVersion = "$NewMajorVersion.$currentMinor$($currentSuffix)"
$versionJson."version" = $newVersion
$versionJson | ConvertTo-Json | Out-File $rootVersionJsonFile
Write-Host "Set version in $rootVersionJsonFile from $currentVersion to $newVersion"
# Update SDK version
$sdkVersionJsonFile = Join-Path $rootDir "sources\GeneratorSdk\version.json"
$versionJson = Get-Content $sdkVersionJsonFile -raw | ConvertFrom-Json
$currentVersion = $versionJson."version"
$currentMajor, $currentMinor, $currentSuffix = Get-Version $currentVersion
$currentMinor = $NewMajorVersion
$newVersion = "$currentMajor.$currentMinor$($currentSuffix)"
$versionJson."version" = $newVersion
$versionJson | ConvertTo-Json | Out-File $sdkVersionJsonFile
Write-Host "Set version in $sdkVersionJsonFile from $currentVersion to $newVersion"