resolve bugs around versioning

added version caching
This commit is contained in:
Kevin Marquette
2018-08-20 02:11:14 -07:00
parent de13e31542
commit 996b2d9195
2 changed files with 67 additions and 46 deletions

View File

@@ -1,20 +1,21 @@
funciton ImportModule
function ImportModule
{
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)]"
"Cannot find [$path]."
Write-Error -Message "Could not find module manifest [$path]"
}
else
{
$file = Get-Item $path
$name = $file.BaseName
$loaded = Get-Module -Name $name -All -ErrorAction Ignore
if ($loaded)
{
@@ -22,8 +23,8 @@ funciton ImportModule
$loaded | Remove-Module -Force
}
"Importing Module [$name] from [$($path.fullname)]..."
Import-Module -FullyQualifiedName $path.fullname -Force -PassThru:$PassThru
"Importing Module [$name] from [$($file.fullname)]..."
Import-Module -Name $file.fullname -Force -PassThru:$PassThru
}
}

View File

@@ -1,4 +1,4 @@
funciton GetModulePublicInterfaceMap
function GetModulePublicInterfaceMap
{
param($Path)
$module = ImportModule -Path $Path -PassThru
@@ -8,7 +8,7 @@ funciton GetModulePublicInterfaceMap
$module.ExportedAliases.values
)
$data = foreach($command in $exportedCommands)
foreach($command in $exportedCommands)
{
foreach ($parameter in $command.Parameters.Keys)
{
@@ -22,35 +22,48 @@ 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 |
Sort-Object -Property {[version]$_.Version} -Descending |
Select -First 1
[version] $publishedVersion = $publishedModule.Version
[version] $sourceVersion = (Get-Metadata -Path $manifestPath -PropertyName 'ModuleVersion')
" Published version [$publishedVersion]"
$version = $publishedVersion
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
[System.Collections.Generic.HashSet[string]] $publishedInterface = GetModulePublicInterfaceMap -Path (Join-Path $downloadFolder $ModuleName)
[System.Collections.Generic.HashSet[string]] $buildInterface = GetModulePublicInterfaceMap -Path $ManifestPath
$bumpVersionType = 'Patch'
if($publishedInterface.IsSubsetOf($buildInterface))
if( -not $publishedInterface.IsSubsetOf($buildInterface))
{
$bumpVersionType = 'Major'
}
@@ -72,19 +85,26 @@ task SetVersion
}
}
" Steping version [$bumpVersionType]"
$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)
}
$version = [version]::new($version.Major, $version.Minor, $version.Build, $build)
"Using version [$version]"
" Comparing to source version [$sourceVersion]"
if($sourceVersion -gt $version)
{
" Using existing version"
$version = $sourceVersion
}
" Setting version [$version]"
Update-Metadata -Path $ManifestPath -PropertyName 'ModuleVersion' -Value $version
Set-Content -Path $versionFile -Value $versionStamp -NoNewline -Encoding UTF8
if(Test-Path $BuildRoot\fingerprint)
{
Remove-Item $BuildRoot\fingerprint