Skip to content
Open
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
17 changes: 5 additions & 12 deletions Actions/.Modules/ReadSettings.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -595,23 +595,16 @@ function ValidateSettings {
$settings
)
Process {
if ($PSVersionTable.PSVersion.Major -lt 7) {
return
}

$settingsJson = ConvertTo-Json -InputObject $settings -Depth 99 -Compress
$settingsSchemaFile = Join-Path $PSScriptRoot "settings.schema.json" -Resolve

$result = ""
try{
$command = [scriptblock] {
$result = ''
Test-Json -Json $args[0] -SchemaFile $args[1] -ErrorVariable result -ErrorAction SilentlyContinue | Out-Null
return $result
}

if($PSVersionTable.PSVersion.Major -lt 6) { # Test-Json is not available in PS5.1
$result = pwsh -noprofile -Command $command -args $settingsJson, $settingsSchemaFile
}
else {
$result = Invoke-Command -ScriptBlock $command -ArgumentList $settingsJson, $settingsSchemaFile
}
Test-Json -Json $settingsJson -SchemaFile $settingsSchemaFile -ErrorVariable result -ErrorAction SilentlyContinue | Out-Null
}
catch {
OutputWarning "Error validating settings. Error: $($_.Exception.Message)"
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The `DownloadProjectDependencies` action now downloads only artifacts from depen
- Issue 2204 - Workspace compilation ignores vsixFile setting
- Issue 2211 - Cannot create a release if a project contains only test apps
- Issue 2214 - Workspace compilation not working with external dependencies
- Fix "filename or extension is too long" error when validating settings on PS5.1 with large settings JSON
- Issue 2235 - Workspace compilation: only the first `customCodeCops` entry resolved when multiple relative paths were configured. Relative `customCodeCops` paths are now resolved against the project folder before being passed to the compiler.

## v9.0
Expand Down
23 changes: 23 additions & 0 deletions Tests/ReadSettings.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -540,5 +540,28 @@ InModuleScope ReadSettings { # Allows testing of private functions
Pop-Location
Remove-Item -Path $tempName -Recurse -Force
}

It 'ValidateSettings skips validation entirely on PS versions less than 7 without warning' {
Mock OutputWarning { }

$settings = @{ "someProp" = "someValue" }

if ($PSVersionTable.PSVersion.Major -ge 7) {
# On PS7+, the Invoke-Command path is used in-process.
ValidateSettings -settings $settings
}
else {
# On PS < 7, validation is skipped entirely; pwsh should never be called
Mock pwsh { throw "pwsh should not be called on PS < 7" }

ValidateSettings -settings $settings

# Verify pwsh was NOT called
Should -Invoke -CommandName pwsh -Times 0
}

# Verify no warning was output
Should -Invoke -CommandName OutputWarning -Times 0
}
}
}