11# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22# SPDX-License-Identifier: MIT-0
33
4+ import argparse
45import json
56import logging
7+ import os
8+ import sys
9+
10+
11+ DESCRIPTION = """Print 2 tables in GitHub-flavored Markdown that summarize
12+ an execution of CBMC proofs."""
13+
14+
15+ def get_args ():
16+ """Parse arguments for summarize script."""
17+ parser = argparse .ArgumentParser (description = DESCRIPTION )
18+ for arg in [{
19+ "flags" : ["--run-file" ],
20+ "help" : "path to the Litani run.json file" ,
21+ "required" : True ,
22+ }]:
23+ flags = arg .pop ("flags" )
24+ parser .add_argument (* flags , ** arg )
25+ return parser .parse_args ()
626
727
828def _get_max_length_per_column_list (data ):
@@ -56,6 +76,7 @@ def _get_status_and_proof_summaries(run_dict):
5676 run_dict
5777 A dictionary representing a Litani run.
5878
79+
5980 Returns
6081 -------
6182 A list of 2 lists.
@@ -70,8 +91,9 @@ def _get_status_and_proof_summaries(run_dict):
7091 count_statuses [status_pretty_name ] += 1
7192 except KeyError :
7293 count_statuses [status_pretty_name ] = 1
73- proof = proof_pipeline ["name" ]
74- proofs .append ([proof , status_pretty_name ])
94+ if proof_pipeline ["name" ] == "print_tool_versions" :
95+ continue
96+ proofs .append ([proof_pipeline ["name" ], status_pretty_name ])
7597 statuses = [["Status" , "Count" ]]
7698 for status , count in count_statuses .items ():
7799 statuses .append ([status , str (count )])
@@ -83,10 +105,39 @@ def print_proof_results(out_file):
83105 Print 2 strings that summarize the proof results.
84106 When printing, each string will render as a GitHub flavored Markdown table.
85107 """
108+ output = "## Summary of CBMC proof results\n \n "
109+ with open (out_file , encoding = 'utf-8' ) as run_json :
110+ run_dict = json .load (run_json )
111+ status_table , proof_table = _get_status_and_proof_summaries (run_dict )
112+ for summary in (status_table , proof_table ):
113+ output += _get_rendered_table (summary )
114+
115+ print (output )
116+ sys .stdout .flush ()
117+
118+ github_summary_file = os .getenv ("GITHUB_STEP_SUMMARY" )
119+ if github_summary_file :
120+ with open (github_summary_file , "a" ) as handle :
121+ print (output , file = handle )
122+ handle .flush ()
123+ else :
124+ logging .warning (
125+ "$GITHUB_STEP_SUMMARY not set, not writing summary file" )
126+
127+ msg = (
128+ "Click the 'Summary' button to view a Markdown table "
129+ "summarizing all proof results" )
130+ if run_dict ["status" ] != "success" :
131+ logging .error ("Not all proofs passed." )
132+ logging .error (msg )
133+ sys .exit (1 )
134+ logging .info (msg )
135+
136+
137+ if __name__ == '__main__' :
138+ args = get_args ()
139+ logging .basicConfig (format = "%(levelname)s: %(message)s" )
86140 try :
87- with open (out_file , encoding = 'utf-8' ) as run_json :
88- run_dict = json .load (run_json )
89- for summary in _get_status_and_proof_summaries (run_dict ):
90- print (_get_rendered_table (summary ))
141+ print_proof_results (args .run_file )
91142 except Exception as ex : # pylint: disable=broad-except
92143 logging .critical ("Could not print results. Exception: %s" , str (ex ))
0 commit comments