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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions Evergreen/Private/Get-InstallerType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Get-InstallerType {
classic = "Classic"
debug = "Debug"
grouppolicy = "GroupPolicy"
hybridCRT = "HybridCRT"
legacy = "Legacy"
light = "Light"
minimalist = "Minimal"
Expand Down
44 changes: 44 additions & 0 deletions Evergreen/Private/Set-ObjectProperty.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 2 additions & 2 deletions Evergreen/Shared/Get-SourceForgeRepoRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Private/Set-ObjectProperty.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
1 change: 1 addition & 0 deletions tests/Shared/Get-AdoptiumTemurin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-AmazonCorretto.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-AzulZulu.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-BellSoftLibericaJDK.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-ElgatoApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
5 changes: 5 additions & 0 deletions tests/Shared/Get-GitHubRepoRelease.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 <Function>" -ForEach @(
@{
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-GitLabRepoRelease.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-HashicorpApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-JetBrainsApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-OperaApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-OracleJava.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Get-SourceForgeRepoRelease.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions tests/Shared/Resolve-MicrosoftFwLink.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading