Skip to content

Commit ec514d7

Browse files
Update-PSResource: Include local-copy prerelease string when deciding update applicability (#1954)
1 parent 5b65686 commit ec514d7

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/code/UpdatePSResource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ private string[] ProcessPackageNames(
390390
}
391391

392392
// If the current package is out of range, install it with the correct version.
393-
if (!NuGetVersion.TryParse(installedPackage.Version.ToString(), out NuGetVersion installedVersion))
393+
string installedVersionString = Utils.GetThreeDigitNormalizedVersionString(installedPackage.Version.ToString(), installedPackage.Prerelease);
394+
if (!NuGetVersion.TryParse(installedVersionString, out NuGetVersion installedVersion))
394395
{
395396
WriteWarning($"Cannot parse nuget version in installed package '{installedPackage.Name}'. Cannot update package.");
396397
continue;

test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ Describe 'Test HTTP Update-PSResource for V2 Server Protocol' -tags 'CI' {
1313
$testModuleName = "test_module"
1414
$testModuleName2 = "test_module2"
1515
$testModuleName3 = "TestModule99"
16+
$testModuleName4 = "TestModulePrerelease"
1617
$PackageManagement = "PackageManagement"
1718
Get-NewPSResourceRepositoryFile
1819
Get-PSResourceRepository
1920
}
2021

2122
AfterEach {
22-
Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "test_module2", "test_script" -Version "*" -ErrorAction SilentlyContinue -SkipDependencyCheck
23+
Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "test_module2", "test_script", "TestModulePrerelease" -Version "*" -ErrorAction SilentlyContinue -SkipDependencyCheck
2324
}
2425

2526
AfterAll {
@@ -210,6 +211,20 @@ Describe 'Test HTTP Update-PSResource for V2 Server Protocol' -tags 'CI' {
210211
$isPkgUpdated | Should -Be $true
211212
}
212213

214+
It "Update prerelease version to next version when prerelease label is only differing factor between versions" {
215+
# $testModuleName4 (TestModulePrerelease) has versions: 0.0.4-beta, 0.0.4. Updating should respect prerelease label
216+
Install-PSResource -Name $testModuleName4 -Version "0.0.4-beta" -Repository $PSGalleryName -TrustRepository
217+
$res = Get-InstalledPSResource -Name $testModuleName4
218+
$res.Name | Should -Be $testModuleName4
219+
$res.Version | Should -Contain "0.0.4"
220+
$res.Prerelease | Should -Be "beta"
221+
222+
Update-PSResource -Name $testModuleName4 -Repository $PSGalleryName -TrustRepository
223+
$res2 = Get-InstalledPSResource -Name $testModuleName4
224+
$res2.Version | Should -Contain "0.0.4"
225+
$res2.Prerelease | Should -BeNullOrEmpty
226+
}
227+
213228
# Windows only
214229
It "update resource under CurrentUser scope" -skip:(!($IsWindows -and (Test-IsAdmin))) {
215230
# TODO: perhaps also install TestModule with the highest version (the one above 1.2.0.0) to the AllUsers path too

0 commit comments

Comments
 (0)