-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUpdateModVersion.ps1
More file actions
74 lines (60 loc) · 2.5 KB
/
UpdateModVersion.ps1
File metadata and controls
74 lines (60 loc) · 2.5 KB
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
<#
.SYNOPSIS
Updates the version number of a module in project.json file. Uses [semver] object type.
.DESCRIPTION
This script updates the version number of a PowerShell module by modifying the project.json file, which gets written into module manifest file (.psd1). [semver] is supported only powershell 7 and above.
It increments the version number based on the specified version part (Major, Minor, Patch). Can also attach preview/stable release to Release property of
.PARAMETER Label
The part of the version number to increment (Major, Minor, Patch). Default is patch.
.PARAMETER PreviewRelease
Use this to use semantic version and attach release name as 'preview' which is supported by PowerShell gallery, to remove it use stable release parameter
.EXAMPLE
Update-MTModuleVersion -Label Major
Updates the Major version part of the module. Version 2.1.3 will become 3.1.3
.EXAMPLE
Update-MTModuleVersion
Updates the Patch version part of the module. Version 2.1.3 will become 2.1.4
.NOTES
Ensure you are in project directory when you run this command.
#>
function Update-MTModuleVersion {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[ValidateSet('Major', 'Minor', 'Patch')]
[string]$Label = 'Patch',
[switch]$PreviewRelease,
[switch]$StableRelease
)
Write-Verbose 'Running Version Update'
$data = Get-MTProjectInfo
$jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json
[semver]$CurrentVersion = $jsonContent.Version
if ($Label -eq 'Major') {
$Major = $CurrentVersion.Major + 1
$Minor = 0
$Patch = 0
} elseif ($Label -eq 'Minor') {
$Major = $CurrentVersion.Major
$Minor = $CurrentVersion.Minor + 1
$Patch = 0
} elseif ($Label -eq 'Patch') {
$Major = $CurrentVersion.Major
$Minor = $CurrentVersion.Minor
$Patch = $CurrentVersion.Patch + 1
}
if ($PreviewRelease) {
$ReleaseType = 'preview'
} elseif ($StableRelease) {
$ReleaseType = $null
} else {
$ReleaseType = $CurrentVersion.PreReleaseLabel
}
$newVersion = [semver]::new($Major, $Minor, $Patch, $ReleaseType, $null)
# Update the version in the JSON object
$jsonContent.Version = $newVersion.ToString()
Write-Host "Version bumped to : $newVersion"
# Convert the JSON object back to JSON format
$newJsonContent = $jsonContent | ConvertTo-Json
# Write the updated JSON back to the file
$newJsonContent | Set-Content -Path $data.ProjecJSON
}