Skip to content

Commit 74e2321

Browse files
committed
fix: Final alignment adjustments for report tables
- Fine-tunes the padding and alignment of the failure comparison table and the final build report to ensure a clean and consistent layout.
1 parent 3a0e5f8 commit 74e2321

File tree

1 file changed

+97
-81
lines changed

1 file changed

+97
-81
lines changed

infra/build/functions/report_generator.py

Lines changed: 97 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import json
2020
import os
2121
import sys
22-
import textwrap
2322

2423
# Define the expected result files for each build version.
2524
RESULT_FILES = {
@@ -28,102 +27,119 @@
2827
'Ubuntu 24.04': 'ubuntu-24-04-results.json',
2928
}
3029

30+
def get_visible_width(text):
31+
"""Calculates the visible width of a string containing emojis."""
32+
width = 0
33+
for char in text:
34+
if char in ['✅', '❌', '⏩']:
35+
width += 2
36+
else:
37+
width += 1
38+
return width
3139

3240
def _print_box(title, lines):
33-
"""Prints a formatted box with a title and lines."""
34-
box_width = 80
35-
title_line = f'║ {title.center(box_width - 4)} ║'
36-
summary_lines = [
37-
'╔' + '═' * (box_width - 2) + '╗',
38-
title_line,
39-
'╠' + '═' * (box_width - 2) + '╣',
40-
]
41-
for line in lines:
42-
summary_lines.append(f'║ {line.ljust(box_width - 4)} ║')
43-
summary_lines.append('╚' + '═' * (box_width - 2) + '╝')
44-
print('\n'.join(summary_lines))
41+
"""Prints a formatted box with a title and lines."""
42+
box_width = 80
43+
title_line = f'║ {title.center(box_width - 4)} ║'
44+
summary_lines = [
45+
'╔' + '═' * (box_width - 2) + '╗',
46+
title_line,
47+
'╠' + '═' * (box_width - 2) + '╣',
48+
]
49+
for line in lines:
50+
padding = box_width - 4 - get_visible_width(line)
51+
summary_lines.append(f'║ {line}{" " * padding} ║')
52+
53+
summary_lines.append('╚' + '═' * (box_width - 2) + '╝')
54+
print('\n'.join(summary_lines))
4555

4656

4757
def generate_final_summary(all_results):
48-
"""Prints a visually appealing summary of all build versions."""
49-
summary_lines = []
50-
for version, data in all_results.items():
51-
if data:
52-
passed = str(data['successful'])
53-
failed = str(data['failed'])
54-
skipped = str(data['skipped'])
55-
total = str(data['total'])
56-
line = (
57-
f" {version.ljust(15)} ► Passed: {passed.ljust(2)} | "
58-
f"Failed: {failed.ljust(2)} | Skipped: {skipped.ljust(2)} | "
59-
f"Total: {total.ljust(2)}")
60-
summary_lines.append(line)
61-
62-
_print_box('FINAL BUILD REPORT', summary_lines)
58+
"""Prints a visually appealing summary of all build versions."""
59+
summary_lines = []
60+
for version, data in all_results.items():
61+
if data:
62+
passed = str(data['successful'])
63+
failed = str(data['failed'])
64+
skipped = str(data['skipped'])
65+
total = str(data['total'])
66+
line = (
67+
f" {version.ljust(15)}{'Passed:'.ljust(8)} {passed.ljust(2)} | "
68+
f"{'Failed:'.ljust(8)} {failed.ljust(2)} | {'Skipped:'.ljust(8)} {skipped.ljust(2)} | "
69+
f"{'Total:'.ljust(8)} {total.ljust(2)}")
70+
summary_lines.append(line)
71+
72+
_print_box('FINAL BUILD REPORT', summary_lines)
6373

6474

6575
def generate_comparison_table(all_results):
66-
"""Prints a table comparing failures across versions."""
67-
all_projects = set()
68-
for data in all_results.values():
69-
if data and 'all_projects' in data:
70-
all_projects.update(data['all_projects'])
71-
72-
if not all_projects:
73-
print('\n✅ No projects were run.')
74-
return
75-
76-
header = ('Project'.ljust(20) + ' | ' + 'Legacy'.center(15) + ' | ' +
77-
'Ubuntu 20.04'.center(15) + ' | ' + 'Ubuntu 24.04'.center(15))
78-
separator = ('-' * 21 + '+' + '-' * 17 + '+' + '-' * 17 + '+' + '-' * 17)
79-
table_lines = [header, separator]
80-
81-
for project in sorted(list(all_projects)):
82-
row_parts = [f' {project.ljust(19)}']
83-
for version in RESULT_FILES:
84-
status_icon = '❓'
85-
if all_results.get(version):
86-
if project in all_results[version].get('failed_projects', []):
87-
status_icon = '❌'
88-
elif project in all_results[version].get('skipped_projects', []):
89-
status_icon = '➡️'
90-
else:
91-
status_icon = '✅'
92-
row_parts.append(f' {status_icon.center(15)} ')
93-
table_lines.append('|'.join(row_parts))
94-
95-
_print_box('FAILURE COMPARISON TABLE', table_lines)
76+
"""Prints a table comparing failures across versions."""
77+
all_projects = set()
78+
for data in all_results.values():
79+
if data and 'all_projects' in data:
80+
all_projects.update(data['all_projects'])
81+
82+
if not all_projects:
83+
print('\n✅ No projects were run.')
84+
return
85+
86+
project_col_width = 18
87+
header = ' Project | Legacy | Ubuntu 20.04 | Ubuntu 24.04'
88+
separator = '-------------------+------------------+------------------+------------------'
89+
90+
table_lines = [header, separator]
91+
92+
for project in sorted(list(all_projects)):
93+
project_name = project
94+
if len(project_name) > project_col_width:
95+
project_name = project_name[:project_col_width - 3] + '...'
96+
97+
row = f' {project_name.ljust(project_col_width)}|'
98+
for version in RESULT_FILES:
99+
status_icon = ' '
100+
if all_results.get(version):
101+
if project in all_results[version].get('failed_projects', []):
102+
status_icon = '❌'
103+
elif project in all_results[version].get('skipped_projects', []):
104+
status_icon = '⏩'
105+
else:
106+
status_icon = '✅'
107+
row += f' {status_icon.center(15)} |'
108+
row = row[:-1]
109+
table_lines.append(row)
110+
111+
_print_box('FAILURE COMPARISON TABLE', table_lines)
96112

97113

98114
def main():
99-
"""Main function to generate report and determine pipeline status."""
100-
all_results = {}
101-
any_failures = False
115+
"""Main function to generate report and determine pipeline status."""
116+
all_results = {}
117+
any_failures = False
102118

103-
print('Generating final build report...')
119+
print('Generating final build report...')
104120

105-
for version, filename in RESULT_FILES.items():
106-
if not os.path.exists(filename):
107-
print(f'Warning: Result file "{filename}" not found.')
108-
all_results[version] = None
109-
continue
121+
for version, filename in RESULT_FILES.items():
122+
if not os.path.exists(filename):
123+
print(f'Warning: Result file "{filename}" not found.')
124+
all_results[version] = None
125+
continue
110126

111-
with open(filename, 'r') as f:
112-
data = json.load(f)
113-
all_results[version] = data
114-
if data['failed'] > 0:
115-
any_failures = True
127+
with open(filename, 'r') as f:
128+
data = json.load(f)
129+
all_results[version] = data
130+
if data['failed'] > 0:
131+
any_failures = True
116132

117-
generate_comparison_table(all_results)
118-
generate_final_summary(all_results)
133+
generate_comparison_table(all_results)
134+
generate_final_summary(all_results)
119135

120-
if any_failures:
121-
print('\nPipeline finished with failures.')
122-
sys.exit(1)
123-
else:
124-
print('\nPipeline finished successfully.')
125-
sys.exit(0)
136+
if any_failures:
137+
print('\nPipeline finished with failures.')
138+
sys.exit(1)
139+
else:
140+
print('\nPipeline finished successfully.')
141+
sys.exit(0)
126142

127143

128144
if __name__ == '__main__':
129-
main()
145+
main()

0 commit comments

Comments
 (0)