Skip to content

Commit

Permalink
Enable multiline outputs
Browse files Browse the repository at this point in the history
Simply copying set_env for now.

Fixes #31
  • Loading branch information
SaschaMann committed Jul 13, 2023
1 parent b796c4b commit 25a6183
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/GitHubActions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ set_command_echo(enable) = command("echo", (), enable ? "on" : "off")
Set the output with name `k` to value `v`.
"""
set_output(k, v) = add_to_file("GITHUB_OUTPUT", "$k=$v")
function set_output(k, v)
val = cmd_value(v)
delimiter = "EOF"
while occursin(delimiter, val)
delimiter *= "EOF"
end
add_to_file("GITHUB_OUTPUT", join(["$k<<$delimiter", val, delimiter], "\n"))
end

"""
set_secret(v)
Expand Down
11 changes: 9 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ const GHA = GitHubActions
@test (@capture_out set_command_echo(false)) == "::echo::off\n"

mktemp() do file, io
withenv("GITHUB_OUTPUT" => file) do
withenv("GITHUB_OUTPUT" => file, map(c -> string(c) => nothing, 'a':'z')...) do
set_output("a", "b")
@test read(file, String) == "a=b\n"
@test read(file, String) == "a<<EOF\nb\nEOF\n"
set_output("b", "fooEOFbar")
@test read(file, String) == "a<<EOF\nb\nEOF\nb<<EOFEOF\nfooEOFbar\nEOFEOF\n"
rm(file)
set_output("c", [])
@test read(file, String) == "c<<EOF\n[]\nEOF\n"
set_output("d", nothing)
@test read(file, String) == "c<<EOF\n[]\nEOF\nd<<EOF\n\nEOF\n"
end
end

Expand Down

0 comments on commit 25a6183

Please sign in to comment.