Skip to content

Commit 29095e5

Browse files
committed
Add support for using env variables
1 parent eda8360 commit 29095e5

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pip install github-action-utils
2727

2828
This section documents all the functions provided by `github-action-utils`. The functions in the package should be used inside a workflow run.
2929

30+
**Note:** You can run the commands using python's `subprocess` module by using `use_subprocess` function parameter or `COMMANDS_USE_SUBPROCESS` environment variable.
31+
3032
### **`echo(message, use_subprocess=False)`**
3133

3234
Prints specified message to the action workflow console.

github_action_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
ACTION_ENV_DELIMITER: str = "__ENV_DELIMITER__"
3131
COMMAND_MARKER: str = "::"
3232

33+
COMMANDS_USE_SUBPROCESS: bool = bool(os.environ.get("COMMANDS_USE_SUBPROCESS", False))
34+
3335

3436
def _print_command(
3537
command: CommandTypes,
@@ -57,7 +59,7 @@ def _print_command(
5759
f"{COMMAND_MARKER}{command_message}"
5860
)
5961

60-
if use_subprocess:
62+
if use_subprocess or COMMANDS_USE_SUBPROCESS:
6163
subprocess.run(["echo", full_command])
6264
else:
6365
print(full_command)
@@ -167,7 +169,7 @@ def echo(message: Any, use_subprocess: bool = False) -> None:
167169
"""
168170
message = str(message)
169171

170-
if use_subprocess:
172+
if use_subprocess or COMMANDS_USE_SUBPROCESS:
171173
subprocess.run(["echo", message])
172174
else:
173175
print(message)
@@ -381,7 +383,7 @@ def end_group(use_subprocess: bool = False) -> None:
381383
"""
382384
message = f"{COMMAND_MARKER}endgroup{COMMAND_MARKER}"
383385

384-
if use_subprocess:
386+
if use_subprocess or COMMANDS_USE_SUBPROCESS:
385387
subprocess.run(["echo", message])
386388
else:
387389
print(message)
@@ -451,7 +453,7 @@ def end_stop_commands(token: str, use_subprocess: bool = False) -> None:
451453
"""
452454
message = f"{COMMAND_MARKER}{token}{COMMAND_MARKER}"
453455

454-
if use_subprocess:
456+
if use_subprocess or COMMANDS_USE_SUBPROCESS:
455457
subprocess.run(["echo", message])
456458
else:
457459
print(message)

0 commit comments

Comments
 (0)