From c7c7e689a8f71ccc7677f5cb6169100ae700bff5 Mon Sep 17 00:00:00 2001 From: fynnbe Date: Thu, 24 Oct 2024 16:21:45 +0200 Subject: [PATCH] add set_github_warning --- bioimageio/spec/_internal/gh_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bioimageio/spec/_internal/gh_utils.py diff --git a/bioimageio/spec/_internal/gh_utils.py b/bioimageio/spec/_internal/gh_utils.py new file mode 100644 index 00000000..88537307 --- /dev/null +++ b/bioimageio/spec/_internal/gh_utils.py @@ -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}" + )