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
46 changes: 46 additions & 0 deletions ci/get-next-package-version.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Tests for ci/get-next-package-version.ps1, which labels a publish with the
# highest version in the release plan.
#
# Each test copies the script to a throwaway folder beside a packages.ps1
# whose release plan is the versions the test gives, so the test states the
# plan it labels.

Describe 'get-next-package-version.ps1' {
BeforeAll {
$script:Label = Join-Path $PSScriptRoot 'get-next-package-version.ps1'

function Get-Label([string[]]$Versions) {
$folder = Join-Path ([IO.Path]::GetTempPath()) `
([Guid]::NewGuid().ToString())
$null = New-Item -ItemType Directory $folder
try {
Copy-Item $script:Label $folder
$list = ($Versions | ForEach-Object { "'$_'" }) -join ', '
Set-Content (Join-Path $folder 'packages.ps1') @"
function Get-ReleasePlan(`$RepoPath) {
@(@($list) | ForEach-Object {
[pscustomobject]@{ Name = "package-`$_"; Version = `$_ }
})
}
"@
& (Join-Path $folder 'get-next-package-version.ps1') `
-RepoName 'repository' -VariableName 'TestLabel'
return $global:TestLabel
} finally {
Remove-Item -Recurse -Force $folder
}
}
}

It 'labels a plan of one package with its whole version' {
Get-Label @('4.5.3') | Should -Be '4.5.3'
}

It 'labels a plan of several packages with the highest version' {
Get-Label @('4.5.3', '4.5.10', '4.5.9') | Should -Be '4.5.10'
}

It 'gives a valid version when nothing is released' {
Get-Label @() | Should -Be '4.5.0'
}
}
2 changes: 1 addition & 1 deletion ci/get-next-package-version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ErrorActionPreference = "Stop"
# build-package.ps1 and publish-package.ps1, all from the same release plan.
$plan = @(Get-ReleasePlan $RepoName)
if ($plan.Count -gt 0) {
$label = ($plan.Version | Sort-Object { [version]$_ })[-1]
$label = @($plan.Version | Sort-Object { [version]$_ })[-1]
} else {
# Nothing to release. Any valid version will do, because
# package-update-required.ps1 stops the publish before it is used.
Expand Down
Loading