Skip to content

Commit

Permalink
add set_github_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Oct 24, 2024
1 parent d744140 commit c7c7e68
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bioimageio/spec/_internal/gh_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import inspect
import os

from loguru import logger


def set_github_warning(title: str, message: str):
if (
not os.getenv("GITHUB_ACTIONS")
or (current_frame := inspect.currentframe()) is None
or (caller_frame := current_frame.f_back) is None
):
# fallback to regular logging
logger.opt(depth=1).warning("{}: {}", title, message)
return

frameinfo = inspect.getframeinfo(caller_frame)
frameinfo.lineno

# log according to
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
print(
f"::warning file={frameinfo.filename},"
+ f"line={frameinfo.lineno},endLine={frameinfo.lineno+1},"
+ f"title={title}::{message}"
)

0 comments on commit c7c7e68

Please sign in to comment.