Skip to content

Commit

Permalink
Merge pull request #5 from philips-software/chore/deprecate-set-output
Browse files Browse the repository at this point in the history
chore: deprecate set output
  • Loading branch information
edwardvandevorst-philips authored Oct 28, 2022
2 parents 7998ef3 + 41db4c6 commit 51c1a6c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 30 deletions.
24 changes: 18 additions & 6 deletions src/parse_input_extra_args.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@

Describe "parse_input_extra_args" {
BeforeEach{
function toGitHub () {
param(
$output_name,
$output_value
)
Write-Output "$output_name=$output_value";
}
Mock toGitHub -MockWith { Write-Output "$output_name=$output_value";}
}

Context "when nothing set" {
It "it should return nothing" {
.\parse_input_extra_args.ps1 | Should -BeNullOrEmpty
Expand All @@ -9,23 +21,23 @@ Describe "parse_input_extra_args" {
It "it should return envNames" {
$envNames = '@NAME1, NAME2'
.\parse_input_extra_args.ps1 -envNames $envNames | Should -Be `
"::set-output name=extra_args:: --env NAME1 --env NAME2 "
"extra_args= --env NAME1 --env NAME2 "
}
}

Context "when entrypoint set" {
It "it should return entrypoint" {
$entryPoint = '@pwsh.exe'
.\parse_input_extra_args.ps1 -entryPoint $entryPoint | Should -Be `
"::set-output name=extra_args:: --entrypoint pwsh.exe"
"extra_args= --entrypoint pwsh.exe"
}
}

Context "when extra_args set" {
It "it should return extra args" {
$extraArgs = '@--test 123456'
.\parse_input_extra_args.ps1 -extraArgs $extraArgs | Should -Be `
"::set-output name=extra_args::--test 123456 "
"extra_args=--test 123456 "
}
}

Expand All @@ -34,7 +46,7 @@ Describe "parse_input_extra_args" {
$entryPoint = '@pwsh.exe'
$extraArgs = '@--test 123456'
.\parse_input_extra_args.ps1 -entryPoint $entryPoint -extraArgs $extraArgs | Should -Be `
"::set-output name=extra_args::--test 123456 --entrypoint pwsh.exe"
"extra_args=--test 123456 --entrypoint pwsh.exe"
}
}

Expand All @@ -43,7 +55,7 @@ Describe "parse_input_extra_args" {
$entryPoint = '@pwsh.exe'
$envNames = '@NAME1,NAME2'
.\parse_input_extra_args.ps1 -entryPoint $entryPoint -envNames $envNames | Should -Be `
"::set-output name=extra_args:: --env NAME1 --env NAME2 --entrypoint pwsh.exe"
"extra_args= --env NAME1 --env NAME2 --entrypoint pwsh.exe"
}
}

Expand All @@ -53,7 +65,7 @@ Describe "parse_input_extra_args" {
$envNames = '@NAME1,NAME2'
$extraArgs = '@--test 123456'
.\parse_input_extra_args.ps1 -entryPoint $entryPoint -envNames $envNames -extraArgs $extraArgs | Should -Be `
"::set-output name=extra_args::--test 123456 --env NAME1 --env NAME2 --entrypoint pwsh.exe"
"extra_args=--test 123456 --env NAME1 --env NAME2 --entrypoint pwsh.exe"
}
}
}
53 changes: 32 additions & 21 deletions src/parse_input_paths.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
Describe "parse_input_paths" {
BeforeEach{
function toGitHub () {
param(
$output_name,
$output_value
)
Write-Output "$output_name=$output_value";
}
Mock toGitHub -MockWith { Write-Output "$output_name=$output_value";}
}

Context "when workspace, mapping, work not set" {
It "it should return gitworkspace" {
$githubWorkSpace = '@github_work_space'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace | Should -Be `
"::set-output name=workspace_path::github_work_space", `
"::set-output name=mapping_path::github_work_space", `
"::set-output name=work_path::github_work_space"
"workspace_path=github_work_space", `
"mapping_path=github_work_space", `
"work_path=github_work_space"
}
}

Expand All @@ -14,9 +25,9 @@ Describe "parse_input_paths" {
$githubWorkSpace = '@github_work_space'
$workSpace = '@work_space'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -workspacePath $workSpace | Should -Be `
"::set-output name=workspace_path::work_space", `
"::set-output name=mapping_path::work_space", `
"::set-output name=work_path::work_space"
"workspace_path=work_space", `
"mapping_path=work_space", `
"work_path=work_space"
}
}

Expand All @@ -26,9 +37,9 @@ Describe "parse_input_paths" {
$workSpace = '@work_space'
$mapping = '@mapping'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -workspacePath $workSpace -mappingPath $mapping | Should -Be `
"::set-output name=workspace_path::work_space", `
"::set-output name=mapping_path::mapping", `
"::set-output name=work_path::mapping"
"workspace_path=work_space", `
"mapping_path=mapping", `
"work_path=mapping"
}
}

Expand All @@ -39,9 +50,9 @@ Describe "parse_input_paths" {
$mapping = '@mapping'
$work = '@work'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -workspacePath $workSpace -mappingPath $mapping -workPath $work | Should -Be `
"::set-output name=workspace_path::work_space", `
"::set-output name=mapping_path::mapping", `
"::set-output name=work_path::work"
"workspace_path=work_space", `
"mapping_path=mapping", `
"work_path=work"
}
}

Expand All @@ -51,9 +62,9 @@ Describe "parse_input_paths" {
$workSpace = '@work_space'
$work = '@work'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -workspacePath $workSpace -workPath $work | Should -Be `
"::set-output name=workspace_path::work_space", `
"::set-output name=mapping_path::work_space", `
"::set-output name=work_path::work"
"workspace_path=work_space", `
"mapping_path=work_space", `
"work_path=work"
}
}

Expand All @@ -63,9 +74,9 @@ Describe "parse_input_paths" {
$mapping = '@mapping'
$work = '@work'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -mappingPath $mapping -workPath $work | Should -Be `
"::set-output name=workspace_path::github_work_space", `
"::set-output name=mapping_path::mapping", `
"::set-output name=work_path::work"
"workspace_path=github_work_space", `
"mapping_path=mapping", `
"work_path=work"
}
}

Expand All @@ -74,9 +85,9 @@ Describe "parse_input_paths" {
$githubWorkSpace = '@github_work_space'
$mapping = '@mapping'
.\parse_input_paths.ps1 -githubWorkSpace $githubWorkSpace -mappingPath $mapping | Should -Be `
"::set-output name=workspace_path::github_work_space", `
"::set-output name=mapping_path::mapping", `
"::set-output name=work_path::mapping"
"workspace_path=github_work_space", `
"mapping_path=mapping", `
"work_path=mapping"
}
}
}
15 changes: 13 additions & 2 deletions src/set_output_variable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
Describe "set_output_variable" {
BeforeEach{
function toGitHub () {
param(
$output_name,
$output_value
)
Write-Output "$output_name=$output_value";
}
Mock toGitHub -MockWith { Write-Output "$output_name=$output_value";}
}

Context "when val is not used" {
It "it should return empty" {
$name = 'theName'
Expand All @@ -18,15 +29,15 @@ Describe "set_output_variable" {
It "it should return output" {
$name = '@theName'
$val = '@value'
.\set_output_variable.ps1 -name $name -val $val | Should -Be "::set-output name=theName::value"
.\set_output_variable.ps1 -name $name -val $val | Should -Be "theName=value"
}
}

Context "when val is value" {
It "it should return output" {
$name = 'theName'
$val = 'value'
.\set_output_variable.ps1 -name $name -val $val | Should -Be "::set-output name=theName::value"
.\set_output_variable.ps1 -name $name -val $val | Should -Be "theName=value"
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/set_output_variable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ $trimArg = "$invovationPath" + "\trim_arg.ps1";
$trimmed_name = & $trimArg -arg $name;
$trimmed_val = & $trimArg -arg $val;

function toGitHub {
param(
$output_name,
$output_value
)
"$output_name=$output_value" >> $env:GITHUB_OUTPUT;
}

if ( ${trimmed_val}.Trim(' ') -ne "" )
{
Write-Output "::set-output name=$trimmed_name::$trimmed_val";
toGitHub -output_name "$trimmed_name" -output_value "$trimmed_val";
}

0 comments on commit 51c1a6c

Please sign in to comment.