diff --git a/CHANGELOG.md b/CHANGELOG.md index b5549dfb..0306825a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change log +## VERSION + +* Added the `Set-ObjectProperty` function to update a property on a PowerShell object when its value matches an expected value, with support for `-WhatIf` and `-Confirm` parameters. +* In `Resolve-MicrosoftFwLink.ps1`, normalized the `Date` field by converting it to a DateTime object using `ConvertTo-DateTime`. +* In `Get-InstallerType.ps1`, added a new installer type `hybridCRT` to the recognized types. +* In `Get-SourceForgeRepoRelease.ps1`, reordered the creation of the output object to group related fields together for clarity. + ## 2611.2874.0 Makes release Date values consistent across Evergreen apps by returning invariant `yyyy-MM-dd` strings instead of culture-dependent DateTime objects. This change is intended to make the `Date` property output more consistent across applications. diff --git a/Evergreen/Private/Get-InstallerType.ps1 b/Evergreen/Private/Get-InstallerType.ps1 index 626b6939..994524f1 100644 --- a/Evergreen/Private/Get-InstallerType.ps1 +++ b/Evergreen/Private/Get-InstallerType.ps1 @@ -23,6 +23,7 @@ function Get-InstallerType { classic = "Classic" debug = "Debug" grouppolicy = "GroupPolicy" + hybridCRT = "HybridCRT" legacy = "Legacy" light = "Light" minimalist = "Minimal" diff --git a/Evergreen/Private/Set-ObjectProperty.ps1 b/Evergreen/Private/Set-ObjectProperty.ps1 new file mode 100644 index 00000000..86a10175 --- /dev/null +++ b/Evergreen/Private/Set-ObjectProperty.ps1 @@ -0,0 +1,44 @@ +<# + .SYNOPSIS + Replaces an object's property value when it matches the expected value. + .DESCRIPTION + Updates the object in place and outputs it whether or not a change is made. + Use -WhatIf to preview matching updates or -Confirm to approve each update. +#> +function Set-ObjectProperty { + [CmdletBinding(SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param( + [Parameter(Mandatory, ValueFromPipeline)] + [pscustomobject]$InputObject, + + [Parameter(Mandatory)] + [string]$PropertyName, + + [Parameter(Mandatory)] + [AllowNull()] + [AllowEmptyString()] + [AllowEmptyCollection()] + [object]$CurrentValue, + + [Parameter(Mandatory)] + [AllowNull()] + [AllowEmptyString()] + [AllowEmptyCollection()] + [object]$Value + ) + + process { + $property = $InputObject.PSObject.Properties[$PropertyName] + if ($null -eq $property) { + throw "Property '$PropertyName' does not exist on the input object." + } + + if ([System.Management.Automation.LanguagePrimitives]::Equals($property.Value, $CurrentValue, $true) -and + $PSCmdlet.ShouldProcess($property.Name, "Set object property")) { + $property.Value = $Value + } + + $InputObject + } +} diff --git a/Evergreen/Shared/Get-SourceForgeRepoRelease.ps1 b/Evergreen/Shared/Get-SourceForgeRepoRelease.ps1 index ffa8422e..e173e0ec 100644 --- a/Evergreen/Shared/Get-SourceForgeRepoRelease.ps1 +++ b/Evergreen/Shared/Get-SourceForgeRepoRelease.ps1 @@ -120,10 +120,10 @@ # Create the output object $PSObject = [PSCustomObject] @{ Version = $Version - Architecture = Get-Architecture -String $FileName - Type = [System.IO.Path]::GetExtension($FileName).TrimStart(".") Size = $item.content.filesize Md5 = $item.content.hash.'#text' + Architecture = Get-Architecture -String $FileName + Type = [System.IO.Path]::GetExtension($FileName).TrimStart(".") FileName = $FileName URI = $Url } diff --git a/tests/Private/Set-ObjectProperty.Tests.ps1 b/tests/Private/Set-ObjectProperty.Tests.ps1 new file mode 100644 index 00000000..3c346cec --- /dev/null +++ b/tests/Private/Set-ObjectProperty.Tests.ps1 @@ -0,0 +1,27 @@ +Describe -Name "Set-ObjectProperty" { + It "Outputs the original object without updating a matching property under WhatIf" { + InModuleScope -ModuleName "Evergreen" { + $Object = [PSCustomObject]@{ Status = "Pending" } + + $Result = $Object | Set-ObjectProperty -PropertyName "Status" -CurrentValue "Pending" -Value "Complete" -WhatIf + + [object]::ReferenceEquals($Result, $Object) | Should -BeTrue + $Object.Status | Should -BeExactly "Pending" + } + } + + It "Updates only matching properties when confirmation is suppressed" { + InModuleScope -ModuleName "Evergreen" { + $Objects = @( + [PSCustomObject]@{ Status = "Pending" } + [PSCustomObject]@{ Status = "Skipped" } + ) + + $Result = @($Objects | Set-ObjectProperty -PropertyName "Status" -CurrentValue "Pending" -Value "Complete" -Confirm:$false) + + $Result.Count | Should -Be 2 + $Objects[0].Status | Should -BeExactly "Complete" + $Objects[1].Status | Should -BeExactly "Skipped" + } + } +} diff --git a/tests/Shared/Get-AdoptiumTemurin.Tests.ps1 b/tests/Shared/Get-AdoptiumTemurin.Tests.ps1 index 11bec7de..9a59bde8 100644 --- a/tests/Shared/Get-AdoptiumTemurin.Tests.ps1 +++ b/tests/Shared/Get-AdoptiumTemurin.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-AmazonCorretto.Tests.ps1 b/tests/Shared/Get-AmazonCorretto.Tests.ps1 index 4e149eca..31426824 100644 --- a/tests/Shared/Get-AmazonCorretto.Tests.ps1 +++ b/tests/Shared/Get-AmazonCorretto.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-AzulZulu.Tests.ps1 b/tests/Shared/Get-AzulZulu.Tests.ps1 index 2adf2045..d1ba644f 100644 --- a/tests/Shared/Get-AzulZulu.Tests.ps1 +++ b/tests/Shared/Get-AzulZulu.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-BellSoftLibericaJDK.Tests.ps1 b/tests/Shared/Get-BellSoftLibericaJDK.Tests.ps1 index 27f1c38e..7e7d0e80 100644 --- a/tests/Shared/Get-BellSoftLibericaJDK.Tests.ps1 +++ b/tests/Shared/Get-BellSoftLibericaJDK.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-ElgatoApp.Tests.ps1 b/tests/Shared/Get-ElgatoApp.Tests.ps1 index 0d10ea64..3bda7027 100644 --- a/tests/Shared/Get-ElgatoApp.Tests.ps1 +++ b/tests/Shared/Get-ElgatoApp.Tests.ps1 @@ -3,6 +3,7 @@ Shared Pester function tests. #> [OutputType()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-GitHubRepoRelease.Tests.ps1 b/tests/Shared/Get-GitHubRepoRelease.Tests.ps1 index 60dc05a9..808f6f72 100644 --- a/tests/Shared/Get-GitHubRepoRelease.Tests.ps1 +++ b/tests/Shared/Get-GitHubRepoRelease.Tests.ps1 @@ -1,3 +1,8 @@ +[OutputType()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] +param () + InModuleScope -ModuleName "Evergreen" { Describe "Repository helper " -ForEach @( @{ diff --git a/tests/Shared/Get-GitLabRepoRelease.Tests.ps1 b/tests/Shared/Get-GitLabRepoRelease.Tests.ps1 index 05810bba..8d33dd76 100644 --- a/tests/Shared/Get-GitLabRepoRelease.Tests.ps1 +++ b/tests/Shared/Get-GitLabRepoRelease.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () BeforeDiscovery { diff --git a/tests/Shared/Get-HashicorpApp.Tests.ps1 b/tests/Shared/Get-HashicorpApp.Tests.ps1 index 0656604f..4dc673b8 100644 --- a/tests/Shared/Get-HashicorpApp.Tests.ps1 +++ b/tests/Shared/Get-HashicorpApp.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-JetBrainsApp.Tests.ps1 b/tests/Shared/Get-JetBrainsApp.Tests.ps1 index 5de3dd3a..7ee7dffb 100644 --- a/tests/Shared/Get-JetBrainsApp.Tests.ps1 +++ b/tests/Shared/Get-JetBrainsApp.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-OperaApp.Tests.ps1 b/tests/Shared/Get-OperaApp.Tests.ps1 index 438d2e09..5feb1113 100644 --- a/tests/Shared/Get-OperaApp.Tests.ps1 +++ b/tests/Shared/Get-OperaApp.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-OracleJava.Tests.ps1 b/tests/Shared/Get-OracleJava.Tests.ps1 index 66e8a018..edd4f786 100644 --- a/tests/Shared/Get-OracleJava.Tests.ps1 +++ b/tests/Shared/Get-OracleJava.Tests.ps1 @@ -3,6 +3,7 @@ Shared Pester function tests. #> [OutputType()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Get-SourceForgeRepoRelease.Tests.ps1 b/tests/Shared/Get-SourceForgeRepoRelease.Tests.ps1 index 9d558ad3..14e5bdb5 100644 --- a/tests/Shared/Get-SourceForgeRepoRelease.Tests.ps1 +++ b/tests/Shared/Get-SourceForgeRepoRelease.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" { diff --git a/tests/Shared/Resolve-MicrosoftFwLink.Tests.ps1 b/tests/Shared/Resolve-MicrosoftFwLink.Tests.ps1 index 88a558e1..2e6676fe 100644 --- a/tests/Shared/Resolve-MicrosoftFwLink.Tests.ps1 +++ b/tests/Shared/Resolve-MicrosoftFwLink.Tests.ps1 @@ -4,6 +4,7 @@ #> [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleCommands", "", Justification = "PowerShell 7.4 or above will be used")] param () InModuleScope -ModuleName "Evergreen" {