File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -42,4 +42,10 @@ defmodule ElixirScript.Core do
42
42
Command . issue_command ( 'set-output' , name , CommandUtils . to_command_value ( value ) )
43
43
end
44
44
end
45
+
46
+ def log_output do
47
+ if System . get_env ( "GITHUB_OUTPUT" ) do
48
+ EnvironmentFileCommand . log_output ( )
49
+ end
50
+ end
45
51
end
Original file line number Diff line number Diff line change @@ -44,4 +44,58 @@ defmodule ElixirScript.GitHubActions.EnvironmentFileCommand do
44
44
"#{ key } <<#{ delimiter } \n #{ command_value } \n #{ delimiter } "
45
45
end
46
46
end
47
+
48
+ @ doc """
49
+ Logs the given `content` to the console. If a `label` is provided, it is
50
+ printed before the content, and the content is indented by two spaces.
51
+
52
+ ## Examples
53
+
54
+ iex> ElixirScript.GitHubActions.EnvironmentFileCommand.log_content("Hello, world!", "Greeting")
55
+ Greeting:
56
+ Hello, world!
57
+
58
+ iex> ElixirScript.GitHubActions.EnvironmentFileCommand.log_content("Hello, world!")
59
+ Hello, world!
60
+
61
+ """
62
+ def log_content ( content , label \\ nil ) do
63
+ indented_content = String . replace ( content , "\n " , "\n " )
64
+
65
+ case label do
66
+ nil -> IO . puts ( indented_content )
67
+ _ -> IO . puts ( "#{ label } :\n #{ indented_content } " )
68
+ end
69
+ end
70
+
71
+ @ doc """
72
+ Logs the contents of the files specified by the "GITHUB_OUTPUT" and "GITHUB_ENV"
73
+ environment variables to the console, each under its own labeled section.
74
+
75
+ ## Example
76
+
77
+ # Assuming GITHUB_OUTPUT and GITHUB_ENV are set to valid file paths
78
+ # with the contents "output content" and "env content" respectively.
79
+ iex> ElixirScript.GitHubActions.EnvironmentFileCommand.log_output()
80
+ ::group::Set outputs
81
+ GITHUB_OUTPUT:
82
+ output content
83
+ GITHUB_ENV:
84
+ env content
85
+ ::endgroup::
86
+ """
87
+ def log_output do
88
+ IO . puts "::group::Set outputs"
89
+ "GITHUB_OUTPUT"
90
+ |> System . get_env ( )
91
+ |> File . read! ( )
92
+ |> log_content ( "GITHUB_OUTPUT" )
93
+
94
+ "GITHUB_ENV"
95
+ |> System . get_env ( )
96
+ |> File . read! ( )
97
+ |> log_content ( "GITHUB_ENV" )
98
+
99
+ IO . puts "::endgroup::"
100
+ end
47
101
end
You can’t perform that action at this time.
0 commit comments