Skip to content

Commit

Permalink
SQ -> Continuous Integration: Export warnings as warning annotations …
Browse files Browse the repository at this point in the history
…in GitHub Actions
  • Loading branch information
davidfstr committed Jan 8, 2024
1 parent 32c3d91 commit f6f13e4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/crystal/tests/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,25 @@ def _warnings_sent_to_ci() -> Iterator[None]:
super_showwarning = warnings.showwarning # capture

def showwarning(message, category, filename, lineno, file=None, line=None):
# Try to reformat `filename` to use the Linux format so that warning
# annotations are associated with the correct file
#
# Depending on OS, `filename` initially looks like:
# - macOS: setup/dist/Crystal Web Archiver.app/Contents/Resources/lib/python38.zip/crystal/tests/index.py
# - Linux: src/crystal/tests/index.py
# - Windows: crystal\tests\index.pyc
filename_parts = filename.split(os.path.sep)
if 'crystal' in filename_parts:
filename_parts = ['src'] + filename_parts[filename_parts.index('crystal'):]
if filename_parts[-1].endswith('.pyc'):
filename_parts[-1] = filename_parts[-1][:-1] # convert .pyc ending to .py
filename = '/'.join(filename_parts) # reinterpret

# Create warning annotation in GitHub Action's [Summary > Annotations] section
#
# 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
Expand Down

0 comments on commit f6f13e4

Please sign in to comment.