|
1 | 1 | import json
|
2 | 2 | import os
|
| 3 | +import secrets |
3 | 4 | import subprocess
|
4 | 5 | import sys
|
5 | 6 | import uuid
|
|
27 | 28 | CommandTypes = str
|
28 | 29 | LogCommandTypes = str
|
29 | 30 |
|
30 |
| - |
31 |
| -ACTION_ENV_DELIMITER: str = "__ENV_DELIMITER__" |
32 | 31 | COMMAND_MARKER: str = "::"
|
33 | 32 |
|
34 | 33 | COMMANDS_USE_SUBPROCESS: bool = bool(os.environ.get("COMMANDS_USE_SUBPROCESS", False))
|
@@ -137,32 +136,17 @@ def _build_options_string(**kwargs: Any) -> str:
|
137 | 136 | )
|
138 | 137 |
|
139 | 138 |
|
140 |
| -def _build_file_input(name: str, value: Any) -> bytes: |
141 |
| - return ( |
142 |
| - f"{_escape_property(name)}" |
143 |
| - f"<<{ACTION_ENV_DELIMITER}\n" |
144 |
| - f"{_escape_data(value)}\n" |
145 |
| - f"{ACTION_ENV_DELIMITER}\n".encode("utf-8") |
146 |
| - ) |
| 139 | +def _build_file_input(name: str, value: str) -> str: |
| 140 | + delimiter = secrets.token_hex() |
| 141 | + return f"{_escape_property(name)}<<{delimiter}\n{value}\n{delimiter}\n" |
147 | 142 |
|
148 | 143 |
|
149 |
| -def set_output(name: str, value: Any, use_subprocess: Union[bool, None] = None) -> None: |
| 144 | +def set_output(name: str, value: str) -> None: |
150 | 145 | """
|
151 |
| - sets out for your workflow using GITHUB_OUTPUT file. |
152 |
| -
|
153 |
| - :param name: name of the output |
154 |
| - :param value: value of the output |
155 |
| - :returns: None |
| 146 | + set workflow output using GITHUB_OUTPUT file. |
156 | 147 | """
|
157 |
| - if use_subprocess is not None: |
158 |
| - warn( |
159 |
| - "Argument `use_subprocess` for `set_output()` is deprecated and " |
160 |
| - "going to be removed in the next version.", |
161 |
| - DeprecationWarning, |
162 |
| - ) |
163 |
| - |
164 |
| - with open(os.environ["GITHUB_OUTPUT"], "ab") as f: |
165 |
| - f.write(_build_file_input(name, value)) |
| 148 | + with open(os.environ["GITHUB_OUTPUT"], "a") as fp: |
| 149 | + fp.write(_build_file_input(name, value)) |
166 | 150 |
|
167 | 151 |
|
168 | 152 | def echo(message: Any, use_subprocess: bool = False) -> None:
|
@@ -326,24 +310,13 @@ def error(
|
326 | 310 | )
|
327 | 311 |
|
328 | 312 |
|
329 |
| -def save_state(name: str, value: Any, use_subprocess: Union[bool, None] = None) -> None: |
| 313 | +def save_state(name: str, value: str) -> None: |
330 | 314 | """
|
331 |
| - sets state for your workflow using $GITHUB_STATE file |
| 315 | + set state for your workflow using $GITHUB_STATE file |
332 | 316 | for sharing it with your workflow's pre: or post: actions.
|
333 |
| -
|
334 |
| - :param name: Name of the state environment variable (e.g: STATE_{name}) |
335 |
| - :param value: value of the state environment variable |
336 |
| - :returns: None |
337 | 317 | """
|
338 |
| - if use_subprocess is not None: |
339 |
| - warn( |
340 |
| - "Argument `use_subprocess` for `save_state()` is deprecated and " |
341 |
| - "going to be removed in the next version.", |
342 |
| - DeprecationWarning, |
343 |
| - ) |
344 |
| - |
345 |
| - with open(os.environ["GITHUB_STATE"], "ab") as f: |
346 |
| - f.write(_build_file_input(name, value)) |
| 318 | + with open(os.environ["GITHUB_STATE"], "a") as fp: |
| 319 | + fp.write(_build_file_input(name, value)) |
347 | 320 |
|
348 | 321 |
|
349 | 322 | def get_state(name: str) -> Union[str, None]:
|
@@ -484,16 +457,12 @@ def stop_commands(
|
484 | 457 | end_stop_commands(stop_token, use_subprocess=use_subprocess)
|
485 | 458 |
|
486 | 459 |
|
487 |
| -def set_env(name: str, value: Any) -> None: |
| 460 | +def set_env(name: str, value: str) -> None: |
488 | 461 | """
|
489 |
| - sets an environment variable for your workflows $GITHUB_ENV file. |
490 |
| -
|
491 |
| - :param name: name of the environment variable |
492 |
| - :param value: value of the environment variable |
493 |
| - :returns: None |
| 462 | + set an environment variable for your workflows $GITHUB_ENV file. |
494 | 463 | """
|
495 |
| - with open(os.environ["GITHUB_ENV"], "ab") as f: |
496 |
| - f.write(_build_file_input(name, value)) |
| 464 | + with open(os.environ["GITHUB_ENV"], "a") as fp: |
| 465 | + fp.write(_build_file_input(name, value)) |
497 | 466 |
|
498 | 467 |
|
499 | 468 | def get_workflow_environment_variables() -> Dict[str, Any]:
|
|
0 commit comments