Change the way version numbers are generated

This commit is contained in:
Kevin Marquette
2018-08-19 20:12:05 -07:00
parent c386851a06
commit de13e31542
5 changed files with 116 additions and 117 deletions

View File

@@ -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
}
}

View File

@@ -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"
}

View File

@@ -1,20 +1,32 @@
funciton ImportModule
{
param(
[string]$path,
[switch]$PassThru
)
task ImportModule {
if (-not(Test-Path -Path $ManifestPath))
$file = Get-ChildItem $path
$name = $file.BaseName
if (-not(Test-Path -Path $path))
{
"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."
"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
}

View 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
}
}