-
Notifications
You must be signed in to change notification settings - Fork 940
ci: add python script to summarize github actions failure logs #10776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||
| import sys | ||||||||||||||||||||
| import re | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def parse_ci_log(log_file_path): | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Reads a CI text log and extracts errors and failed tests. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| errors_found = [] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| try: | ||||||||||||||||||||
| with open(log_file_path, 'r', encoding='utf-8') as file: | ||||||||||||||||||||
| for line in file: | ||||||||||||||||||||
| # Search for lines containing the word 'error' | ||||||||||||||||||||
| if re.search(r'\berror\b', line, re.IGNORECASE): | ||||||||||||||||||||
| errors_found.append(line.strip()) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Search for lines indicating a failed test | ||||||||||||||||||||
| elif 'FAIL:' in line: | ||||||||||||||||||||
| errors_found.append(line.strip()) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| except FileNotFoundError: | ||||||||||||||||||||
| print(f"Error: Could not find log file at {log_file_path}") | ||||||||||||||||||||
| return | ||||||||||||||||||||
|
Comment on lines
+21
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the log file is not found, the script prints an error message to standard output (
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # Format the output nicely using Markdown | ||||||||||||||||||||
| print("### 🚨 CI Failure Summary") | ||||||||||||||||||||
| if not errors_found: | ||||||||||||||||||||
| print("No explicit errors found in the log.") | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| print(f"Found {len(errors_found)} critical issues:") | ||||||||||||||||||||
| for err in errors_found[:10]: # Cap at 10 to avoid spamming the PR | ||||||||||||||||||||
| print(f"- `{err}`") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # This allows the script to be run directly from the command line | ||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||
| if len(sys.argv) < 2: | ||||||||||||||||||||
| print("Usage: python3 ci_summarizer.py <path_to_log_file>") | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| parse_ci_log(sys.argv[1]) | ||||||||||||||||||||
|
Comment on lines
+36
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the script is invoked with incorrect arguments, it prints the usage message to standard output (
Suggested change
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI logs can sometimes contain invalid UTF-8 byte sequences (e.g., from compiler warnings, binary outputs, or localized tools). Opening the file with strict UTF-8 decoding can cause the script to crash with a
UnicodeDecodeError, preventing the summary from being generated.Using
errors='replace'orerrors='ignore'ensures the script remains robust and processes the entire log file successfully.