From bfc94b6e0222cde538118adc4e1c31db611c2de4 Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Mon, 25 Nov 2024 16:41:48 +0100 Subject: [PATCH] Tools: output ccache and diff size output to github action summary --- Tools/scripts/build_tests/pretty_diff_size.py | 15 +++++++++++++++ Tools/scripts/build_tests/test_ccache.py | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Tools/scripts/build_tests/pretty_diff_size.py b/Tools/scripts/build_tests/pretty_diff_size.py index 79598d706f..59d0c1eade 100755 --- a/Tools/scripts/build_tests/pretty_diff_size.py +++ b/Tools/scripts/build_tests/pretty_diff_size.py @@ -90,6 +90,21 @@ def print_table(summary_data_list_second, summary_data_list_master): print_data.append(col_data) print(tabulate(print_data, headers=["Binary Name", "Text [B]", "Data [B]", "BSS (B)", "Total Flash Change [B] (%)", "Flash Free After PR (B)"])) + # Get the GitHub Actions summary file path + summary_file = os.getenv('GITHUB_STEP_SUMMARY') + if summary_file: + # Append the output to the summary file + with open(summary_file, 'a') as f: + f.write("### Diff summary\n") + f.write(tabulate(print_data, headers=[ + "Binary Name", + "Text [B]", + "Data [B]", + "BSS (B)", + "Total Flash Change [B] (%)", + "Flash Free After PR (B)" + ], tablefmt="github")) + f.write("\n") def extract_binaries_size(path): diff --git a/Tools/scripts/build_tests/test_ccache.py b/Tools/scripts/build_tests/test_ccache.py index c0d5543d1e..9abdb22bad 100755 --- a/Tools/scripts/build_tests/test_ccache.py +++ b/Tools/scripts/build_tests/test_ccache.py @@ -65,11 +65,22 @@ subprocess.run(["ccache", "-C", "-z"]) build_board(boards[0]) subprocess.run(["ccache", "-z"]) build_board(boards[1]) -subprocess.run(["ccache", "-s"]) +result = subprocess.run(["ccache", "-s"], capture_output=True, text=True) +print(result.stdout) + +# Get the GitHub Actions summary file path +summary_file = os.getenv('GITHUB_STEP_SUMMARY') post = ccache_stats() hit_pct = 100 * post[0] / float(post[0]+post[1]) print("ccache hit percentage: %.1f%% %s" % (hit_pct, post)) +if summary_file: + # Append the output to the summary file + with open(summary_file, 'a') as f: + f.write(f"### ccache -s Output with {boards}\n") + f.write(f"```\n{result.stdout}\n```\n") + f.write(f"### ccache hit percentage (min {args.min_cache_pct})\n") + f.write("ccache hit percentage: %.1f%% %s\n" % (hit_pct, post)) if hit_pct < args.min_cache_pct: print("ccache hits too low, need %d%%" % args.min_cache_pct) sys.exit(1)