Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -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.3",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "Manjunath Beli",
Expand Down
8 changes: 6 additions & 2 deletions src/private/Build.Manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 22 additions & 14 deletions src/public/UpdateModVersion.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading