Skip to content

Commit 965d426

Browse files
authored
Merge pull request #15 from belibug/previewrelease
Add support for preview release tag and uses semver for versioning
2 parents 3ff03de + 580078a commit 965d426

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ProjectName": "ModuleTools",
33
"Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.",
4-
"Version": "1.1.0",
4+
"Version": "1.1.3",
55
"copyResourcesToModuleRoot": false,
66
"Manifest": {
77
"Author": "Manjunath Beli",

src/private/Build.Manifest.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ function Build-Manifest {
1313
}
1414

1515
$ManfiestAllowedParams = (Get-Command New-ModuleManifest).Parameters.Keys
16-
16+
$sv = [semver]$data.Version
1717
$ParmsManifest = @{
1818
Path = $data.ManifestFilePSD1
1919
Description = $data.Description
2020
FunctionsToExport = $functionToExport
2121
AliasesToExport = $aliasToExport
2222
RootModule = "$($data.ProjectName).psm1"
23-
ModuleVersion = $data.Version
23+
ModuleVersion = [version]$sv
2424
}
25+
26+
if ($sv.PreReleaseLabel) {
27+
$ParmsManifest['Prerelease'] = $sv.PreReleaseLabel
28+
}
2529

2630
# Accept only valid Manifest Parameters
2731
$data.Manifest.Keys | ForEach-Object {

src/public/UpdateModVersion.ps1

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<#
22
.SYNOPSIS
3-
Updates the version number of a module in project.json file.
3+
Updates the version number of a module in project.json file. Uses [semver] object type.
44
55
.DESCRIPTION
6-
This script updates the version number of a PowerShell module by modifying the project.json file, which gets written into module manifest file (.psd1).
7-
It increments the version number based on the specified version part (Major, Minor, Patch).
6+
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.
7+
It increments the version number based on the specified version part (Major, Minor, Patch). Can also attach preview/stable release to Release property of
88
99
.PARAMETER Label
1010
The part of the version number to increment (Major, Minor, Patch). Default is patch.
1111
12+
.PARAMETER PreviewRelease
13+
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
14+
1215
.EXAMPLE
1316
Update-MTModuleVersion -Label Major
1417
Updates the Major version part of the module. Version 2.1.3 will become 3.1.3
@@ -24,28 +27,33 @@ function Update-MTModuleVersion {
2427
[CmdletBinding(SupportsShouldProcess = $true)]
2528
param(
2629
[ValidateSet('Major', 'Minor', 'Patch')]
27-
[string]$Label = 'Patch'
30+
[string]$Label = 'Patch',
31+
[switch]$PreviewRelease,
32+
[switch]$StableRelease
2833
)
2934
Write-Verbose 'Running Version Update'
3035

3136
$data = Get-MTProjectInfo
3237
$jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json
3338

34-
$currentVersion = $jsonContent.Version
35-
$versionComponents = $currentVersion.Split('.')
39+
[semver]$CurrentVersion = $jsonContent.Version
3640

37-
# Increment the last component
38-
switch ($Label) {
39-
'Major' { $versionComponents[0] = [int]$versionComponents[0] + 1 }
40-
'Minor' { $versionComponents[1] = [int]$versionComponents[1] + 1 }
41-
'Patch' { $versionComponents[2] = [int]$versionComponents[2] + 1 }
41+
$Major = ($Label -eq 'Major') ? ($CurrentVersion.Major + 1) : $CurrentVersion.Major
42+
$Minor = ($Label -eq 'Minor') ? ($CurrentVersion.Minor + 1) : $CurrentVersion.Minor
43+
$Patch = ($Label -eq 'Patch') ? ($CurrentVersion.Patch + 1) : $CurrentVersion.Patch
44+
45+
if ($PreviewRelease) {
46+
$ReleaseType = 'preview'
47+
} elseif ($StableRelease) {
48+
$ReleaseType = $null
49+
} else {
50+
$ReleaseType = $CurrentVersion.PreReleaseLabel
4251
}
4352

44-
# Join the version components back into a string
45-
$newVersion = $versionComponents -join '.'
53+
$newVersion = [semver]::new($Major, $Minor, $Patch, $ReleaseType, $null)
4654

4755
# Update the version in the JSON object
48-
$jsonContent.Version = $newVersion
56+
$jsonContent.Version = $newVersion.ToString()
4957
Write-Host "Version bumped to : $newVersion"
5058

5159
# Convert the JSON object back to JSON format

0 commit comments

Comments
 (0)