Skip to content

Commit

Permalink
Continuous Integration: Export warnings as warning annotations in Git…
Browse files Browse the repository at this point in the history
…Hub Actions
  • Loading branch information
davidfstr committed Jan 7, 2024
1 parent 84c813f commit 26644cb
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/crystal/tests/index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import contextmanager
from crystal.tests import (
test_addgroup,
test_addrooturl,
Expand Down Expand Up @@ -34,7 +35,7 @@
import sys
import time
import traceback
from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple
from typing import Any, Callable, Coroutine, Dict, List, Iterator, Optional, Tuple
from unittest import SkipTest
import warnings

Expand Down Expand Up @@ -232,3 +233,27 @@ def _run_tests(test_names: List[str]) -> bool:
print()

return is_ok


@contextmanager
def _warnings_sent_to_ci() -> Iterator[None]:
if not _running_in_ci():
yield
return

super_showwarning = warnings.showwarning # capture

def showwarning(message, category, filename, lineno, file=None, line=None):
# Syntax: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-setting-a-warning-message
print(f'::warning file={filename},line={lineno}::{message}')
return super_showwarning(message, category, filename, lineno, file, line)

warnings.showwarning = showwarning
try:
yield
finally:
warnings.showwarning = super_showwarning


def _running_in_ci() -> bool:
return os.environ.get('GITHUB_ACTIONS') == 'true'

0 comments on commit 26644cb

Please sign in to comment.