Coverage for bioimageio/spec/_internal/gh_utils.py: 40%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-02-05 13:53 +0000

1import inspect 

2import os 

3 

4from loguru import logger 

5 

6 

7def set_github_warning(title: str, message: str): 

8 if ( 

9 not os.getenv("GITHUB_ACTIONS") 

10 or (current_frame := inspect.currentframe()) is None 

11 or (caller_frame := current_frame.f_back) is None 

12 ): 

13 # fallback to regular logging 

14 logger.opt(depth=1).warning("{}: {}", title, message) 

15 return 

16 

17 frameinfo = inspect.getframeinfo(caller_frame) 

18 frameinfo.lineno 

19 

20 # log according to 

21 # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message 

22 print( 

23 f"::warning file={frameinfo.filename}," 

24 + f"line={frameinfo.lineno},endLine={frameinfo.lineno+1}," 

25 + f"title={title}::{message}" 

26 )