+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions github_action_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
CommandTypes = Literal[
"add-mask",
"debug",
"endgroup",
"error",
"group",
"notice",
Expand All @@ -35,19 +34,23 @@ def _print_command(
command: CommandTypes,
command_message: str,
options_string: Union[str] = "",
escape_message: bool = True,
) -> None:
"""
Helper function to print GitHub action commands to the shell.
Docs: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions

:param command: command name from `CommandTypes`
:param command_message: message string
:returns: None
"""
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
if escape_message:
command_message = _escape_data(command_message)

echo_message = (
f"{COMMAND_MARKER}{command} "
f"{options_string or ''}"
f"{COMMAND_MARKER}{_escape_data(command_message)}"
f"{COMMAND_MARKER}{command_message}"
)

print(echo_message)
Expand Down Expand Up @@ -148,7 +151,7 @@ def echo(message: Any) -> None:
:param message: Any type of message e.g. string, number, list, dict
:returns: None
"""
print(_escape_data(message))
print(message)


def debug(message: str) -> None:
Expand All @@ -161,10 +164,7 @@ def debug(message: str) -> None:
:param message: message string
:returns: None
"""
_print_command(
"debug",
message,
)
_print_command("debug", message, escape_message=False)


def notice(
Expand Down Expand Up @@ -202,6 +202,7 @@ def notice(
line=line,
end_line=end_line,
),
escape_message=False,
)


Expand Down Expand Up @@ -240,6 +241,7 @@ def warning(
line=line,
end_line=end_line,
),
escape_message=False,
)


Expand Down Expand Up @@ -278,6 +280,7 @@ def error(
line=line,
end_line=end_line,
),
escape_message=False,
)


Expand Down Expand Up @@ -325,7 +328,7 @@ def start_group(title: str) -> None:
:param title: title of the group
:returns: None
"""
_print_command("group", title)
_print_command("group", title, escape_message=False)


def end_group() -> None:
Expand Down Expand Up @@ -379,7 +382,7 @@ def begin_stop_commands(token: Union[str, None] = None) -> str:
if not token:
token = str(uuid.uuid1())

_print_command("stop-commands", token)
_print_command("stop-commands", token, escape_message=False)

return token

Expand Down
18 changes: 9 additions & 9 deletions tests/test_github_action_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def test__build_options_string(input_kwargs: Any, expected: str) -> None:
"test_input,expected",
[
("test", "test\n"),
("test\n", "test%0A\n"),
("%test", "%25test\n"),
("\rtest", "%0Dtest\n"),
("test\n", "test\n\n"),
("%test", "%test\n"),
("\rtest", "\rtest\n"),
],
)
def test_echo(capfd: Any, test_input: str, expected: str) -> None:
Expand All @@ -136,9 +136,9 @@ def test_echo(capfd: Any, test_input: str, expected: str) -> None:
"test_input,expected",
[
("test", "::debug ::test\n"),
("test\n", "::debug ::test%0A\n"),
("%test", "::debug ::%25test\n"),
("\rtest", "::debug ::%0Dtest\n"),
("test\n", "::debug ::test\n\n"),
("%test", "::debug ::%test\n"),
("\rtest", "::debug ::\rtest\n"),
],
)
def test_debug(capfd: Any, test_input: str, expected: str) -> None:
Expand Down Expand Up @@ -289,9 +289,9 @@ def test_get_user_input() -> None:
"test_input,expected",
[
("test", "::group ::test\n"),
("test\n", "::group ::test%0A\n"),
("%test", "::group ::%25test\n"),
("\rtest", "::group ::%0Dtest\n"),
("test\n", "::group ::test\n\n"),
("%test", "::group ::%test\n"),
("\rtest", "::group ::\rtest\n"),
],
)
def test_start_group(capfd: Any, test_input: str, expected: str) -> None:
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载