Skip to content

Commit

Permalink
adding annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 3, 2024
1 parent 16db683 commit eea6a9d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pyaction/workflow/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import subprocess
from typing import Any, Callable, Dict, get_type_hints

from pydantic import TypeAdapter

from pyaction import io
from pyaction.consts import DEBUG_MODE, Color
from pyaction.utils import check_parameters


Expand Down Expand Up @@ -37,3 +39,45 @@ def write(context: Dict[str, Any]) -> None:
"""

io.write(context) # pragma: no cover

def error(self, title: str) -> None:
"""pops an error annotation
Args:
title (str): the error title
"""

if DEBUG_MODE:
message = f"{Color.BOLD_RED.value}Error: {Color.RESET.value}{title}"
else:
message = f"::error::{title}"

subprocess.call(["echo", message])

def warning(self, title: str) -> None:
"""pops a warning annotation
Args:
title (str): the warning title
"""

if DEBUG_MODE:
message = f"{Color.YELLOW.value}Warning: {Color.RESET.value}{title}"
else:
message = f"::warning::{title}"

subprocess.call(["echo", message])

def notice(self, title: str) -> None:
"""pops a notice annotation
Args:
title (str): the notice title
"""

if DEBUG_MODE:
message = f"{Color.GREY.value}Notice: {Color.RESET.value}{title}"
else:
message = f"::notice::{title}"

subprocess.call(["echo", message])
4 changes: 4 additions & 0 deletions testing_action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

@workflow.action()
def testing_action(test_name: str, test_age: int) -> None:
workflow.warning("This is a warning annotation!")
workflow.notice("This is a notice annotation!")
workflow.error("This is an error annotation!")

workflow.write(
{
"message": rainbowify(f"{test_name}, you are {test_age}!"),
Expand Down

0 comments on commit eea6a9d

Please sign in to comment.