resolve bugs around versioning
added version caching
This commit is contained in:
@@ -1,20 +1,21 @@
|
|||||||
funciton ImportModule
|
function ImportModule
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[string]$path,
|
[string]$path,
|
||||||
[switch]$PassThru
|
[switch]$PassThru
|
||||||
)
|
)
|
||||||
|
|
||||||
$file = Get-ChildItem $path
|
|
||||||
$name = $file.BaseName
|
|
||||||
|
|
||||||
if (-not(Test-Path -Path $path))
|
if (-not(Test-Path -Path $path))
|
||||||
{
|
{
|
||||||
"Cannot find [$($path.fullname)]."
|
"Cannot find [$path]."
|
||||||
Write-Error -Message "Could not find module manifest [$($path.fullname)]"
|
Write-Error -Message "Could not find module manifest [$path]"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$file = Get-Item $path
|
||||||
|
$name = $file.BaseName
|
||||||
|
|
||||||
$loaded = Get-Module -Name $name -All -ErrorAction Ignore
|
$loaded = Get-Module -Name $name -All -ErrorAction Ignore
|
||||||
if ($loaded)
|
if ($loaded)
|
||||||
{
|
{
|
||||||
@@ -22,8 +23,8 @@ funciton ImportModule
|
|||||||
$loaded | Remove-Module -Force
|
$loaded | Remove-Module -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
"Importing Module [$name] from [$($path.fullname)]..."
|
"Importing Module [$name] from [$($file.fullname)]..."
|
||||||
Import-Module -FullyQualifiedName $path.fullname -Force -PassThru:$PassThru
|
Import-Module -Name $file.fullname -Force -PassThru:$PassThru
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
funciton GetModulePublicInterfaceMap
|
function GetModulePublicInterfaceMap
|
||||||
{
|
{
|
||||||
param($Path)
|
param($Path)
|
||||||
$module = ImportModule -Path $Path -PassThru
|
$module = ImportModule -Path $Path -PassThru
|
||||||
@@ -8,7 +8,7 @@ funciton GetModulePublicInterfaceMap
|
|||||||
$module.ExportedAliases.values
|
$module.ExportedAliases.values
|
||||||
)
|
)
|
||||||
|
|
||||||
$data = foreach($command in $exportedCommands)
|
foreach($command in $exportedCommands)
|
||||||
{
|
{
|
||||||
foreach ($parameter in $command.Parameters.Keys)
|
foreach ($parameter in $command.Parameters.Keys)
|
||||||
{
|
{
|
||||||
@@ -22,69 +22,89 @@ funciton GetModulePublicInterfaceMap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[System.Collections.Generic.HashSet[string]]$data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task SetVersion
|
task SetVersion {
|
||||||
{
|
$version = $null
|
||||||
|
|
||||||
|
$versionStamp = (git rev-parse origin/master) + (git rev-parse head)
|
||||||
|
|
||||||
|
"Load current version"
|
||||||
|
[version] $sourceVersion = (Get-Metadata -Path $manifestPath -PropertyName 'ModuleVersion')
|
||||||
|
" Source version [$sourceVersion]"
|
||||||
|
|
||||||
|
$downloadFolder = Join-Path -Path $output downloads
|
||||||
|
$null = New-Item -ItemType Directory -Path $downloadFolder -Force -ErrorAction Ignore
|
||||||
|
|
||||||
|
$versionFile = Join-Path $downloadFolder versionfile
|
||||||
|
if(Test-Path $versionFile)
|
||||||
|
{
|
||||||
|
$versionFileData = Get-Content $versionFile -raw
|
||||||
|
if($versionFileData -eq $versionStamp)
|
||||||
|
{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"Checking for published version"
|
||||||
$publishedModule = Find-Module -Name $ModuleName |
|
$publishedModule = Find-Module -Name $ModuleName |
|
||||||
Sort-Object -Property {[version]$_.Version} -Descending |
|
Sort-Object -Property {[version]$_.Version} -Descending |
|
||||||
Select -First 1
|
Select -First 1
|
||||||
|
|
||||||
[version] $publishedVersion = $publishedModule.Version
|
[version] $publishedVersion = $publishedModule.Version
|
||||||
[version] $sourceVersion = (Get-Metadata -Path $manifestPath -PropertyName 'ModuleVersion')
|
" Published version [$publishedVersion]"
|
||||||
|
|
||||||
if($sourceVersion -gt $publishedVersion)
|
$version = $publishedVersion
|
||||||
|
|
||||||
|
"Downloading published module to check for breaking changes"
|
||||||
|
$publishedModule | Save-Module -Path $downloadFolder
|
||||||
|
|
||||||
|
[System.Collections.Generic.HashSet[string]] $publishedInterface = GetModulePublicInterfaceMap -Path (Join-Path $downloadFolder $ModuleName)
|
||||||
|
[System.Collections.Generic.HashSet[string]] $buildInterface = GetModulePublicInterfaceMap -Path $ManifestPath
|
||||||
|
|
||||||
|
$bumpVersionType = 'Patch'
|
||||||
|
if( -not $publishedInterface.IsSubsetOf($buildInterface))
|
||||||
{
|
{
|
||||||
Write-Verbose "Using existing version as base [$sourceVersion]"
|
$bumpVersionType = 'Major'
|
||||||
$version = $sourceVersion
|
|
||||||
}
|
}
|
||||||
else
|
elseif ($publishedInterface.count -ne $buildInterface.count)
|
||||||
{
|
{
|
||||||
"Downloading published module to check for breaking changes"
|
$bumpVersionType = 'Minor'
|
||||||
$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)
|
if ($version -lt ([version] '1.0.0'))
|
||||||
$buildInterface = GetModulePublicInterfaceMap -Path $ManifestPath
|
{
|
||||||
|
"Module is still in beta; don't bump major version."
|
||||||
$bumpVersionType = 'Patch'
|
if ($bumpVersionType -eq 'Major')
|
||||||
if($publishedInterface.IsSubsetOf($buildInterface))
|
|
||||||
{
|
|
||||||
$bumpVersionType = 'Major'
|
|
||||||
}
|
|
||||||
elseif ($publishedInterface.count -ne $buildInterface.count)
|
|
||||||
{
|
{
|
||||||
$bumpVersionType = 'Minor'
|
$bumpVersionType = 'Minor'
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if ($version -lt ([version] '1.0.0'))
|
|
||||||
{
|
{
|
||||||
"Module is still in beta; don't bump major version."
|
$bumpVersionType = 'Patch'
|
||||||
if ($bumpVersionType -eq 'Major')
|
|
||||||
{
|
|
||||||
$bumpVersionType = 'Minor'
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$bumpVersionType = 'Patch'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = [version] (Step-Version -Version $version -Type $bumpVersionType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$build = -1
|
" Steping version [$bumpVersionType]"
|
||||||
|
$version = [version] (Step-Version -Version $version -Type $bumpVersionType)
|
||||||
|
|
||||||
if ($null -ne $env:Build_BuildID)
|
if ($null -ne $env:Build_BuildID)
|
||||||
{
|
{
|
||||||
$build = $env:Build_BuildID
|
$build = $env:Build_BuildID
|
||||||
|
$version = [version]::new($version.Major, $version.Minor, $version.Build, $build)
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = [version]::new($version.Major, $version.Minor, $version.Build, $build)
|
" Comparing to source version [$sourceVersion]"
|
||||||
"Using version [$version]"
|
if($sourceVersion -gt $version)
|
||||||
|
{
|
||||||
|
" Using existing version"
|
||||||
|
$version = $sourceVersion
|
||||||
|
}
|
||||||
|
" Setting version [$version]"
|
||||||
Update-Metadata -Path $ManifestPath -PropertyName 'ModuleVersion' -Value $version
|
Update-Metadata -Path $ManifestPath -PropertyName 'ModuleVersion' -Value $version
|
||||||
|
|
||||||
|
Set-Content -Path $versionFile -Value $versionStamp -NoNewline -Encoding UTF8
|
||||||
|
|
||||||
if(Test-Path $BuildRoot\fingerprint)
|
if(Test-Path $BuildRoot\fingerprint)
|
||||||
{
|
{
|
||||||
Remove-Item $BuildRoot\fingerprint
|
Remove-Item $BuildRoot\fingerprint
|
||||||
|
|||||||
Reference in New Issue
Block a user