3434def _print_command (
3535 command : CommandTypes ,
3636 command_message : str ,
37- property_string : Union [str , None ] = None ,
37+ options_string : Union [str ] = "" ,
3838) -> None :
3939 """
4040 Helper function to print GitHub action commands to the shell.
@@ -44,14 +44,11 @@ def _print_command(
4444 :returns: None
4545 """
4646 # https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
47- if command == "endgroup" :
48- echo_message = f"{ COMMAND_MARKER } endgroup{ COMMAND_MARKER } "
49- else :
50- echo_message = (
51- f"{ COMMAND_MARKER } { command } "
52- f"{ property_string or '' } "
53- f"{ COMMAND_MARKER } { _escape_data (command_message )} "
54- )
47+ echo_message = (
48+ f"{ COMMAND_MARKER } { command } "
49+ f"{ options_string or '' } "
50+ f"{ COMMAND_MARKER } { _escape_data (command_message )} "
51+ )
5552
5653 print (echo_message )
5754
@@ -119,29 +116,12 @@ def _to_camel_case(text: str) -> str:
119116 return f"{ text [:1 ].lower ()} { text .title ().replace ('_' , '' )[1 :]} "
120117
121118
122- def _print_log_message (
123- command : LogCommandTypes ,
124- message : str ,
125- ** kwargs : Any ,
126- ) -> None :
127- """
128- prints a log message to the GitHub action shell.
129-
130- :param message: Message to display
131- :param title: Custom title
132- :param file: Filename in the repository
133- :param col: Column number, starting at 1
134- :param end_column: End column number
135- :param line: Line number, starting at 1
136- :param end_line: End line number
137- :returns: None
138- """
139- property_sting = "," .join (
119+ def _build_options_string (** kwargs : Any ) -> str :
120+ return "," .join (
140121 f"{ _to_camel_case (key )} ={ _escape_property (value )} "
141122 for key , value in kwargs .items ()
142- if value
123+ if value is not None
143124 )
144- _print_command (command , message , property_string = property_sting )
145125
146126
147127def set_output (name : str , value : Any ) -> None :
@@ -155,8 +135,7 @@ def set_output(name: str, value: Any) -> None:
155135 :param value: value of the output
156136 :returns: None
157137 """
158- property_string = f"name={ _escape_property (name )} "
159- _print_command ("set-output" , value , property_string = property_string )
138+ _print_command ("set-output" , value , options_string = _build_options_string (name = name ))
160139
161140
162141def echo (message : Any ) -> None :
@@ -182,7 +161,10 @@ def debug(message: str) -> None:
182161 :param message: message string
183162 :returns: None
184163 """
185- _print_log_message ("debug" , message )
164+ _print_command (
165+ "debug" ,
166+ message ,
167+ )
186168
187169
188170def notice (
@@ -209,15 +191,17 @@ def notice(
209191 :param end_line: End line number
210192 :returns: None
211193 """
212- _print_log_message (
194+ _print_command (
213195 "notice" ,
214196 message ,
215- title = title ,
216- file = file ,
217- col = col ,
218- end_column = end_column ,
219- line = line ,
220- end_line = end_line ,
197+ options_string = _build_options_string (
198+ title = title ,
199+ file = file ,
200+ col = col ,
201+ end_column = end_column ,
202+ line = line ,
203+ end_line = end_line ,
204+ ),
221205 )
222206
223207
@@ -245,15 +229,17 @@ def warning(
245229 :param end_line: End line number
246230 :returns: None
247231 """
248- _print_log_message (
232+ _print_command (
249233 "warning" ,
250234 message ,
251- title = title ,
252- file = file ,
253- col = col ,
254- end_column = end_column ,
255- line = line ,
256- end_line = end_line ,
235+ options_string = _build_options_string (
236+ title = title ,
237+ file = file ,
238+ col = col ,
239+ end_column = end_column ,
240+ line = line ,
241+ end_line = end_line ,
242+ ),
257243 )
258244
259245
@@ -281,15 +267,17 @@ def error(
281267 :param end_line: End line number
282268 :returns: None
283269 """
284- _print_log_message (
270+ _print_command (
285271 "error" ,
286272 message ,
287- title = title ,
288- file = file ,
289- col = col ,
290- end_column = end_column ,
291- line = line ,
292- end_line = end_line ,
273+ options_string = _build_options_string (
274+ title = title ,
275+ file = file ,
276+ col = col ,
277+ end_column = end_column ,
278+ line = line ,
279+ end_line = end_line ,
280+ ),
293281 )
294282
295283
@@ -304,8 +292,7 @@ def save_state(name: str, value: Any) -> None:
304292 :param value: value of the state environment variable
305293 :returns: None
306294 """
307- property_string = f"name={ _escape_property (name )} "
308- _print_command ("save-state" , value , property_string = property_string )
295+ _print_command ("save-state" , value , options_string = _build_options_string (name = name ))
309296
310297
311298def get_state (name : str ) -> Union [str , None ]:
@@ -350,7 +337,7 @@ def end_group() -> None:
350337
351338 :returns: None
352339 """
353- _print_command ( " endgroup" , " " )
340+ print ( f" { COMMAND_MARKER } endgroup{ COMMAND_MARKER } " )
354341
355342
356343@contextmanager
0 commit comments