diff --git a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 index 39877374a..d6d2a8ba1 100644 --- a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 +++ b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 @@ -71,14 +71,18 @@ Write-Debug 'Property value:' Write-Debug ($InputObject | Out-String) - # Convert hashtable or PSCustomObject to compressed JSON - if ($value -is [hashtable] -or $value -is [PSCustomObject]) { - Write-Debug 'Converting property value to JSON' + # For each property value: + if ($value -is [string]) { + if (Test-Json $value -ErrorAction SilentlyContinue) { + # Normalize valid JSON strings to a consistent format. + $value = ($value | ConvertFrom-Json) | ConvertTo-Json -Compress -Depth 100 + } + } else { + # For non-string values, convert to JSON. $value = $value | ConvertTo-Json -Compress -Depth 100 - Write-Debug 'Property value:' - Write-Debug $value } + $guid = [Guid]::NewGuid().ToString() $EOFMarker = "EOF_$guid" $outputLines += "$key<<$EOFMarker" diff --git a/src/functions/public/Commands/Set-GitHubOutput.ps1 b/src/functions/public/Commands/Set-GitHubOutput.ps1 index bc0094814..afdbcfc6a 100644 --- a/src/functions/public/Commands/Set-GitHubOutput.ps1 +++ b/src/functions/public/Commands/Set-GitHubOutput.ps1 @@ -57,11 +57,6 @@ $Value = $Value | ConvertFrom-SecureString -AsPlainText Add-Mask -Value $Value } - 'Hashtable|PSCustomObject' { - Write-Debug 'Converting value to JSON:' - $Value = $Value | ConvertTo-Json -Compress -Depth 100 - Write-Debug $value - } default {} } @@ -70,6 +65,9 @@ # If the script is running in a GitHub composite action, accumulate the output under the 'result' key, # else append the key-value pair directly. if ($env:PSMODULE_GITHUB_SCRIPT) { + if ($Value -isnot [string]) { + $Value = $Value | ConvertTo-Json -Compress -Depth 100 + } Write-Debug "[$stackPath] - Running in GitHub-Script composite action" if (-not $outputs.ContainsKey('result')) { $outputs['result'] = @{} diff --git a/src/functions/public/Commands/Set-GitHubStepSummary.ps1 b/src/functions/public/Commands/Set-GitHubStepSummary.ps1 index d13bb16f5..531e79a86 100644 --- a/src/functions/public/Commands/Set-GitHubStepSummary.ps1 +++ b/src/functions/public/Commands/Set-GitHubStepSummary.ps1 @@ -34,7 +34,10 @@ [CmdletBinding()] param( # Summary of the step - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline + )] [AllowNull()] [string] $Summary,