Change the way version numbers are generated
This commit is contained in:
@@ -14,93 +14,5 @@ taskx BuildManifest @{
|
||||
'Setting FunctionsToExport...'
|
||||
Set-ModuleFunctions -Name $ManifestPath -FunctionsToExport $functions.BaseName
|
||||
}
|
||||
|
||||
'Detecting semantic versioning...'
|
||||
"Importing Module [$ManifestPath]..."
|
||||
Import-Module -FullyQualifiedName $ManifestPath
|
||||
|
||||
"Get-Command -Module [$ModuleName]..."
|
||||
$commands = Get-Command -Module $ModuleName
|
||||
|
||||
"Removing Module [$ModuleName]..."
|
||||
Remove-Module -Name $ModuleName -Force
|
||||
|
||||
'Calculating fingerprint...'
|
||||
$fingerprint = foreach ($command in $commands)
|
||||
{
|
||||
foreach ($parameter in $command.Parameters.Keys)
|
||||
{
|
||||
if($false -eq $command.Parameters[$parameter].IsDynamic)
|
||||
{
|
||||
'{0}:{1}' -f $command.Name, $command.Parameters[$parameter].Name
|
||||
foreach ($alias in $command.Parameters[$parameter].Aliases)
|
||||
{
|
||||
'{0}:{1}' -f $command.Name, $alias
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fingerprint = $fingerprint | Sort-Object
|
||||
|
||||
if (Test-Path -Path '.\fingerprint')
|
||||
{
|
||||
$oldFingerprint = Get-Content -Path '.\fingerprint'
|
||||
}
|
||||
|
||||
$bumpVersionType = 'Patch'
|
||||
|
||||
'Detecting new features...'
|
||||
$features = $fingerprint |
|
||||
Where-Object { $_ -notin $oldFingerprint }
|
||||
|
||||
foreach ($feature in $features)
|
||||
{
|
||||
$feature
|
||||
$bumpVersionType = 'Minor'
|
||||
}
|
||||
|
||||
'Detecting breaking changes...'
|
||||
$breakingChanges = $oldFingerprint |
|
||||
Where-Object { $_ -notin $fingerprint }
|
||||
|
||||
foreach ($breakingChange in $breakingChanges)
|
||||
{
|
||||
$breakingChange
|
||||
$bumpVersionType = 'Major'
|
||||
}
|
||||
|
||||
Set-Content -Path '.\fingerprint' -Value $fingerprint
|
||||
|
||||
# Bump the module version
|
||||
$version = [version] (Get-Metadata -Path $manifestPath -PropertyName 'ModuleVersion')
|
||||
|
||||
if ($version -lt ([version] '1.0.0'))
|
||||
{
|
||||
"Module is still in beta; don't bump major version."
|
||||
if ($bumpVersionType -eq 'Major')
|
||||
{
|
||||
$bumpVersionType = 'Minor'
|
||||
}
|
||||
else
|
||||
{
|
||||
$bumpVersionType = 'Patch'
|
||||
}
|
||||
}
|
||||
|
||||
"Stepping [$bumpVersionType] version [$version]..."
|
||||
$version = [version] (Step-Version -Version $version -Type $bumpVersionType)
|
||||
|
||||
$build = 1
|
||||
if ($null -ne $env:Build_BuildID)
|
||||
{
|
||||
$build = $env:Build_BuildID
|
||||
}
|
||||
|
||||
$version = [version]::new($version.Major, $version.Minor, $version.Build, $build)
|
||||
"Using version [$version]..."
|
||||
"##vso[build.updatebuildnumber]$version"
|
||||
|
||||
Update-Metadata -Path $ManifestPath -PropertyName 'ModuleVersion' -Value $version
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
|
||||
task ImportDevModule {
|
||||
|
||||
if (-not(Test-Path -Path "$Source\$ModuleName.psd1"))
|
||||
{
|
||||
"Module [$ModuleName] is not built; cannot find [$Source\$ModuleName.psd1]."
|
||||
Write-Error -Message "Could not find module manifest [$Source\$ModuleName.psd1]."
|
||||
}
|
||||
else
|
||||
{
|
||||
$loaded = Get-Module -Name $ModuleName -All
|
||||
if ($loaded)
|
||||
{
|
||||
"Unloading Module [$ModuleName] from a previous import..."
|
||||
$loaded | Remove-Module -Force
|
||||
}
|
||||
|
||||
"Importing Module [$ModuleName] from [$Source\$ModuleName.psd1]..."
|
||||
Import-Module -FullyQualifiedName "$Source\$ModuleName.psd1" -Force
|
||||
}
|
||||
ImportModule -Path "$Source\$ModuleName.psd1"
|
||||
}
|
||||
|
||||
@@ -1,20 +1,32 @@
|
||||
|
||||
task ImportModule {
|
||||
if (-not(Test-Path -Path $ManifestPath))
|
||||
funciton ImportModule
|
||||
{
|
||||
"Module [$ModuleName] is not built; cannot find [$ManifestPath]."
|
||||
Write-Error -Message "Could not find module manifest [$ManifestPath]. You may need to build the module first."
|
||||
param(
|
||||
[string]$path,
|
||||
[switch]$PassThru
|
||||
)
|
||||
|
||||
$file = Get-ChildItem $path
|
||||
$name = $file.BaseName
|
||||
|
||||
if (-not(Test-Path -Path $path))
|
||||
{
|
||||
"Cannot find [$($path.fullname)]."
|
||||
Write-Error -Message "Could not find module manifest [$($path.fullname)]"
|
||||
}
|
||||
else
|
||||
{
|
||||
$loaded = Get-Module -Name $ModuleName -All
|
||||
$loaded = Get-Module -Name $name -All -ErrorAction Ignore
|
||||
if ($loaded)
|
||||
{
|
||||
"Unloading Module [$ModuleName] from a previous import..."
|
||||
"Unloading Module [$name] from a previous import..."
|
||||
$loaded | Remove-Module -Force
|
||||
}
|
||||
|
||||
"Importing Module [$ModuleName] from [$ManifestPath]..."
|
||||
Import-Module -FullyQualifiedName $ManifestPath -Force
|
||||
"Importing Module [$name] from [$($path.fullname)]..."
|
||||
Import-Module -FullyQualifiedName $path.fullname -Force -PassThru:$PassThru
|
||||
}
|
||||
}
|
||||
|
||||
task ImportModule {
|
||||
ImportModule -Path $ManifestPath
|
||||
}
|
||||
|
||||
92
BuildTasks/SetVersion.Task.ps1
Normal file
92
BuildTasks/SetVersion.Task.ps1
Normal file
@@ -0,0 +1,92 @@
|
||||
funciton GetModulePublicInterfaceMap
|
||||
{
|
||||
param($Path)
|
||||
$module = ImportModule -Path $Path -PassThru
|
||||
$exportedCommands = @(
|
||||
$module.ExportedFunctions.values
|
||||
$module.ExportedCmdlets.values
|
||||
$module.ExportedAliases.values
|
||||
)
|
||||
|
||||
$data = foreach($command in $exportedCommands)
|
||||
{
|
||||
foreach ($parameter in $command.Parameters.Keys)
|
||||
{
|
||||
if($false -eq $command.Parameters[$parameter].IsDynamic)
|
||||
{
|
||||
'{0}:{1}' -f $command.Name, $command.Parameters[$parameter].Name
|
||||
foreach ($alias in $command.Parameters[$parameter].Aliases)
|
||||
{
|
||||
'{0}:{1}' -f $command.Name, $alias
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[System.Collections.Generic.HashSet[string]]$data
|
||||
}
|
||||
|
||||
task SetVersion
|
||||
{
|
||||
$publishedModule = Find-Module -Name $ModuleName |
|
||||
Sort-Object -Property {[version]$_.Version} -Descending |
|
||||
Select -First 1
|
||||
|
||||
[version] $publishedVersion = $publishedModule.Version
|
||||
[version] $sourceVersion = (Get-Metadata -Path $manifestPath -PropertyName 'ModuleVersion')
|
||||
|
||||
if($sourceVersion -gt $publishedVersion)
|
||||
{
|
||||
Write-Verbose "Using existing version as base [$sourceVersion]"
|
||||
$version = $sourceVersion
|
||||
}
|
||||
else
|
||||
{
|
||||
"Downloading published module to check for breaking changes"
|
||||
$downloadFolder = Join-Path -Path $output downloads
|
||||
$null = New-Item -ItemType Directory -Path $downloadFolder -Force -ErrorAction Ignore
|
||||
$publishedModule | Save-Module -Path $downloadFolder
|
||||
|
||||
$publishedInterface = GetModulePublicInterfaceMap -Path (Join-Path $downloadFolder $ModuleName)
|
||||
$buildInterface = GetModulePublicInterfaceMap -Path $ManifestPath
|
||||
|
||||
$bumpVersionType = 'Patch'
|
||||
if($publishedInterface.IsSubsetOf($buildInterface))
|
||||
{
|
||||
$bumpVersionType = 'Major'
|
||||
}
|
||||
elseif ($publishedInterface.count -ne $buildInterface.count)
|
||||
{
|
||||
$bumpVersionType = 'Minor'
|
||||
}
|
||||
|
||||
if ($version -lt ([version] '1.0.0'))
|
||||
{
|
||||
"Module is still in beta; don't bump major version."
|
||||
if ($bumpVersionType -eq 'Major')
|
||||
{
|
||||
$bumpVersionType = 'Minor'
|
||||
}
|
||||
else
|
||||
{
|
||||
$bumpVersionType = 'Patch'
|
||||
}
|
||||
}
|
||||
|
||||
$version = [version] (Step-Version -Version $version -Type $bumpVersionType)
|
||||
}
|
||||
|
||||
$build = -1
|
||||
if ($null -ne $env:Build_BuildID)
|
||||
{
|
||||
$build = $env:Build_BuildID
|
||||
}
|
||||
|
||||
$version = [version]::new($version.Major, $version.Minor, $version.Build, $build)
|
||||
"Using version [$version]"
|
||||
Update-Metadata -Path $ManifestPath -PropertyName 'ModuleVersion' -Value $version
|
||||
|
||||
if(Test-Path $BuildRoot\fingerprint)
|
||||
{
|
||||
Remove-Item $BuildRoot\fingerprint
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@ $Script:ModuleName = Get-ChildItem .\*\*.psm1 | Select-object -ExpandProperty Ba
|
||||
$Script:CodeCoveragePercent = 0.0 # 0 to 1
|
||||
. $psscriptroot\BuildTasks\InvokeBuildInit.ps1
|
||||
|
||||
task Default Build, Test, UpdateSource
|
||||
task Build Copy, Compile, BuildModule, BuildManifest, Helpify
|
||||
task Default Build, Test, UpdateSource, Helpify
|
||||
task Build Copy, Compile, BuildModule, BuildManifest, SetVersion
|
||||
task Helpify GenerateMarkdown, GenerateHelp
|
||||
task Test Build, ImportModule, FullTests
|
||||
task Publish Build, Test, PublishModule
|
||||
task Publish Build, Test, Helpify, PublishModule
|
||||
|
||||
Write-Host 'Import common tasks'
|
||||
Get-ChildItem -Path $buildroot\BuildTasks\*.Task.ps1 |
|
||||
|
||||
Reference in New Issue
Block a user