From 6c36fe8cc01c741a5e9acc9ab1b3fd616ae776d8 Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Sun, 14 Sep 2025 11:38:26 -0500 Subject: [PATCH 1/4] Add support for preview release tag and uses semver for versioning --- project.json | 4 ++-- src/public/UpdateModVersion.ps1 | 36 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/project.json b/project.json index c86c16d..4af2494 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,7 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "1.1.0", + "Version": "1.1.1-preview", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli", @@ -19,4 +19,4 @@ "Verbosity": "Detailed" } } -} \ No newline at end of file +} diff --git a/src/public/UpdateModVersion.ps1 b/src/public/UpdateModVersion.ps1 index 6920265..ade6e1b 100644 --- a/src/public/UpdateModVersion.ps1 +++ b/src/public/UpdateModVersion.ps1 @@ -1,14 +1,17 @@ <# .SYNOPSIS -Updates the version number of a module in project.json file. +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). -It increments the version number based on the specified version part (Major, Minor, Patch). +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 @@ -24,28 +27,33 @@ function Update-MTModuleVersion { [CmdletBinding(SupportsShouldProcess = $true)] param( [ValidateSet('Major', 'Minor', 'Patch')] - [string]$Label = 'Patch' + [string]$Label = 'Patch', + [switch]$PreviewRelease, + [switch]$StableRelease ) Write-Verbose 'Running Version Update' $data = Get-MTProjectInfo $jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json - $currentVersion = $jsonContent.Version - $versionComponents = $currentVersion.Split('.') + [semver]$CurrentVersion = $jsonContent.Version - # Increment the last component - switch ($Label) { - 'Major' { $versionComponents[0] = [int]$versionComponents[0] + 1 } - 'Minor' { $versionComponents[1] = [int]$versionComponents[1] + 1 } - 'Patch' { $versionComponents[2] = [int]$versionComponents[2] + 1 } + $Major = ($Label -eq 'Major') ? ($CurrentVersion.Major + 1) : $CurrentVersion.Major + $Minor = ($Label -eq 'Minor') ? ($CurrentVersion.Minor + 1) : $CurrentVersion.Minor + $Patch = ($Label -eq 'Patch') ? ($CurrentVersion.Patch + 1) : $CurrentVersion.Patch + + if ($PreviewRelease) { + $ReleaseType = 'preview' + } elseif ($StableRelease) { + $ReleaseType = $null + } else { + $ReleaseType = $CurrentVersion.PreReleaseLabel } - # Join the version components back into a string - $newVersion = $versionComponents -join '.' + $newVersion = [semver]::new($Major, $Minor, $Patch, $ReleaseType, $null) # Update the version in the JSON object - $jsonContent.Version = $newVersion + $jsonContent.Version = $newVersion.ToString() Write-Host "Version bumped to : $newVersion" # Convert the JSON object back to JSON format From e4afe769e08a1d39618ea124493f1503f7cb8e9e Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Sun, 14 Sep 2025 12:25:34 -0500 Subject: [PATCH 2/4] --- project.json | 2 +- src/private/Build.Manifest.ps1 | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/project.json b/project.json index 4af2494..c7c42e7 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,7 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "1.1.1-preview", + "Version": "1.1.3", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli", diff --git a/src/private/Build.Manifest.ps1 b/src/private/Build.Manifest.ps1 index 0fa0cdc..956be1b 100644 --- a/src/private/Build.Manifest.ps1 +++ b/src/private/Build.Manifest.ps1 @@ -13,15 +13,19 @@ function Build-Manifest { } $ManfiestAllowedParams = (Get-Command New-ModuleManifest).Parameters.Keys - + $sv = [semver]$data.Version $ParmsManifest = @{ Path = $data.ManifestFilePSD1 Description = $data.Description FunctionsToExport = $functionToExport AliasesToExport = $aliasToExport RootModule = "$($data.ProjectName).psm1" - ModuleVersion = $data.Version + ModuleVersion = [version]$sv } + + if ($sv.PreReleaseLabel) { + $ParmsManifest['Prerelease'] = $sv.PreReleaseLabel + } # Accept only valid Manifest Parameters $data.Manifest.Keys | ForEach-Object { From d201a7ed44a33640e5ee2b5a111e68fe22a55560 Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Sun, 14 Sep 2025 12:25:43 -0500 Subject: [PATCH 3/4] Fixed ModuleManifest creation --- project.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.json b/project.json index c7c42e7..37c6ed8 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,7 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "1.1.3", + "Version": "1.1.2-preview", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli", @@ -19,4 +19,4 @@ "Verbosity": "Detailed" } } -} +} \ No newline at end of file From 580078a148c6be6f8957270b55f773a5019e4b0b Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Sun, 14 Sep 2025 12:26:55 -0500 Subject: [PATCH 4/4] updated release --- project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.json b/project.json index 37c6ed8..b37e9c8 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,7 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "1.1.2-preview", + "Version": "1.1.3", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli",