Skip to content

Commit a96b132

Browse files
committed
fix: correctly handle multiline values in Set-ActionOutput
by extension, also Set-ActionVariable is fixed, as it has silently suffered from the same issue since last update. fixes #17
1 parent 4561c4a commit a96b132

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ jobs:
193193
script: |
194194
$props = [ordered]@{ a = 1; b = 'c' }
195195
Set-ActionVariable testvar $props
196+
Set-ActionVariable testvar_multiline "line1`nline2`nline3"
197+
Get-Content $env:GITHUB_ENV -Raw | Write-Host
196198
if ($env:testvar -cne '{"a":1,"b":"c"}') {
197199
throw "unexpected: Set-ActionVariable failed.`n$env:testvar"
198200
}
@@ -203,6 +205,9 @@ jobs:
203205
if ($env:testvar -cne '{"a":1,"b":"c"}') {
204206
throw "unexpected: Set-ActionVariable failed.`n$env:testvar"
205207
}
208+
if ($env:testvar_multiline -cne "line1`nline2`nline3") {
209+
throw "unexpected: Set-ActionVariable failed.`n$env:testvar_multiline"
210+
}
206211
207212
# Set-ActionCommandEcho
208213
- name: Set-ActionCommandEcho test (manual check whether commands are shown in log)

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
* fix: correctly handle multiline values in Set-ActionOutput and Set-ActionVariable.
13+
1014
## [2.0.2] - 2022-10-17
1115

1216
### Changed

lib/GitHubActionsCore/GitHubActionsCore.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Describe 'Set-ActionOutput' {
6262
Context "Given value '<value>'" -Foreach @(
6363
@{ Value = ''; ExpectedCmd = ''; ExpectedEnv = $null }
6464
@{ Value = 'test value'; ExpectedCmd = 'test value'; ExpectedEnv = 'test value' }
65-
@{ Value = "test `n multiline `r`n value"; ExpectedCmd = 'test %0A multiline %0D%0A value'; ExpectedEnv = "test `n multiline `r`n value" }
65+
@{ Value = "test `n multiline `r`n value"; ExpectedCmd = 'test %0A multiline %0D%0A value'; ExpectedEnv = "test `n multiline `r`n value"; Multiline = $true }
6666
@{ Value = 'A % B'; ExpectedCmd = 'A %25 B'; ExpectedEnv = 'A % B' }
6767
@{ Value = [ordered]@{ a = '1x'; b = '2y' }; ExpectedCmd = '{"a":"1x","b":"2y"}'; ExpectedEnv = '{"a":"1x","b":"2y"}' }
6868
) {
@@ -88,7 +88,7 @@ Describe 'Set-ActionOutput' {
8888
Set-ActionOutput 'my-result' $Value
8989

9090
$eol = [System.Environment]::NewLine
91-
if ($ExpectedEnv -contains "`n") {
91+
if ($Multiline) {
9292
$null, $delimiter = (Get-Content $testPath)[0] -split "<<"
9393
Get-Content $testPath -Raw
9494
| Should -BeExactly "my-result<<$delimiter${eol}$ExpectedEnv${eol}$delimiter${eol}"
@@ -131,7 +131,7 @@ Describe 'Set-ActionVariable' {
131131
Context "Given value '<value>'" -Foreach @(
132132
@{ Value = ''; ExpectedCmd = ''; ExpectedEnv = $null }
133133
@{ Value = 'test value'; ExpectedCmd = 'test value'; ExpectedEnv = 'test value' }
134-
@{ Value = "test `n multiline `r`n value"; ExpectedCmd = 'test %0A multiline %0D%0A value'; ExpectedEnv = "test `n multiline `r`n value" }
134+
@{ Value = "test `n multiline `r`n value"; ExpectedCmd = 'test %0A multiline %0D%0A value'; ExpectedEnv = "test `n multiline `r`n value"; Multiline = $true }
135135
@{ Value = 'A % B'; ExpectedCmd = 'A %25 B'; ExpectedEnv = 'A % B' }
136136
@{ Value = [ordered]@{ a = '1x'; b = '2y' }; ExpectedCmd = '{"a":"1x","b":"2y"}'; ExpectedEnv = '{"a":"1x","b":"2y"}' }
137137
) {
@@ -167,7 +167,7 @@ Describe 'Set-ActionVariable' {
167167

168168
$env:TESTVAR | Should -Be $ExpectedEnv
169169
$eol = [System.Environment]::NewLine
170-
if ($ExpectedEnv -contains "`n") {
170+
if ($Multiline) {
171171
$null, $delimiter = (Get-Content $testPath)[0] -split "<<"
172172
Get-Content $testPath -Raw
173173
| Should -BeExactly "TESTVAR<<$delimiter${eol}$ExpectedEnv${eol}$delimiter${eol}"
@@ -182,7 +182,7 @@ Describe 'Set-ActionVariable' {
182182

183183
$env:TESTVAR | Should -BeNullOrEmpty
184184
$eol = [System.Environment]::NewLine
185-
if ($ExpectedEnv -contains "`n") {
185+
if ($Multiline) {
186186
$null, $delimiter = (Get-Content $testPath)[0] -split "<<"
187187
Get-Content $testPath -Raw
188188
| Should -BeExactly "TESTVAR<<$delimiter${eol}$ExpectedEnv${eol}$delimiter${eol}"

lib/GitHubActionsCore/GitHubActionsCore.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ function ConvertTo-ActionKeyValueFileCommand {
678678
[object]$Value
679679
)
680680
$convertedValue = ConvertTo-ActionCommandValue $Value
681-
if (-not ($convertedValue -contains "`n")) {
681+
if ($convertedValue -notmatch '\n') {
682682
return "$Name=$convertedValue"
683683
}
684684
$delimiter = "ghadelimiter_$(New-Guid)"

0 commit comments

Comments
 (0)