|
6 | 6 | from contextlib import contextmanager |
7 | 7 | from functools import lru_cache |
8 | 8 | from typing import Any, Dict, Generator, Union |
| 9 | +from warnings import warn |
9 | 10 |
|
10 | 11 | if sys.version_info >= (3, 8): |
11 | 12 | from typing import Literal |
@@ -136,24 +137,32 @@ def _build_options_string(**kwargs: Any) -> str: |
136 | 137 | ) |
137 | 138 |
|
138 | 139 |
|
139 | | -def set_output(name: str, value: Any, use_subprocess: bool = False) -> None: |
140 | | - """ |
141 | | - Sets an action's output parameter. |
| 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 | + ) |
142 | 147 |
|
143 | | - Template: ::set-output name={name}::{value} |
144 | | - Example: echo "::set-output name=action_fruit::strawberry" |
| 148 | + |
| 149 | +def set_output(name: str, value: Any, use_subprocess: Union[bool, None] = None) -> None: |
| 150 | + """ |
| 151 | + sets out for your workflow using GITHUB_OUTPUT file. |
145 | 152 |
|
146 | 153 | :param name: name of the output |
147 | 154 | :param value: value of the output |
148 | | - :param use_subprocess: use subprocess module to echo command |
149 | 155 | :returns: None |
150 | 156 | """ |
151 | | - _print_command( |
152 | | - "set-output", |
153 | | - value, |
154 | | - options_string=_build_options_string(name=name), |
155 | | - use_subprocess=use_subprocess, |
156 | | - ) |
| 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)) |
157 | 166 |
|
158 | 167 |
|
159 | 168 | def echo(message: Any, use_subprocess: bool = False) -> None: |
@@ -317,24 +326,24 @@ def error( |
317 | 326 | ) |
318 | 327 |
|
319 | 328 |
|
320 | | -def save_state(name: str, value: Any, use_subprocess: bool = False) -> None: |
| 329 | +def save_state(name: str, value: Any, use_subprocess: Union[bool, None] = None) -> None: |
321 | 330 | """ |
322 | | - creates environment variable for sharing with your workflow's pre: or post: actions. |
323 | | -
|
324 | | - Template: ::save-state name={name}::{value} |
325 | | - Example: echo "::save-state name=processID::12345" |
| 331 | + sets state for your workflow using $GITHUB_STATE file |
| 332 | + for sharing it with your workflow's pre: or post: actions. |
326 | 333 |
|
327 | 334 | :param name: Name of the state environment variable (e.g: STATE_{name}) |
328 | 335 | :param value: value of the state environment variable |
329 | | - :param use_subprocess: use subprocess module to echo command |
330 | 336 | :returns: None |
331 | 337 | """ |
332 | | - _print_command( |
333 | | - "save-state", |
334 | | - value, |
335 | | - options_string=_build_options_string(name=name), |
336 | | - use_subprocess=use_subprocess, |
337 | | - ) |
| 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)) |
338 | 347 |
|
339 | 348 |
|
340 | 349 | def get_state(name: str) -> Union[str, None]: |
@@ -484,12 +493,7 @@ def set_env(name: str, value: Any) -> None: |
484 | 493 | :returns: None |
485 | 494 | """ |
486 | 495 | with open(os.environ["GITHUB_ENV"], "ab") as f: |
487 | | - f.write( |
488 | | - f"{_escape_property(name)}" |
489 | | - f"<<{ACTION_ENV_DELIMITER}\n" |
490 | | - f"{_escape_data(value)}\n" |
491 | | - f"{ACTION_ENV_DELIMITER}\n".encode("utf-8") |
492 | | - ) |
| 496 | + f.write(_build_file_input(name, value)) |
493 | 497 |
|
494 | 498 |
|
495 | 499 | def get_workflow_environment_variables() -> Dict[str, Any]: |
|
0 commit comments