@@ -108,7 +108,6 @@ def build_graph(self, graph_spec: GraphSpec):
108108 return False
109109
110110 if build_status == Metadata .STABLE :
111- self .build_results [graph_id ] = {'release_version' : release_version }
112111 logger .info (f'Graph { graph_id } release_version { release_version } was already built.' )
113112 else :
114113 # If we get here we need to build the graph
@@ -147,7 +146,6 @@ def build_graph(self, graph_spec: GraphSpec):
147146 graph_metadata .set_build_info (merge_metadata , current_time )
148147 graph_metadata .set_build_status (Metadata .STABLE )
149148 logger .info (f'Building graph { graph_id } complete!' )
150- self .build_results [graph_id ] = {'release_version' : release_version }
151149
152150 kgx_bundle = KGXBundle (graph_output_dir )
153151
@@ -304,6 +302,7 @@ def build_graph(self, graph_spec: GraphSpec):
304302 kgx_bundle .edges_path .replace (KGXBundle .EDGES_FILENAME , COLLAPSED_QUALIFIERS_FILENAME ))
305303 for jsonl_path in jsonl_files_to_compress :
306304 kgx_bundle .compress_jsonl (jsonl_path )
305+ self ._record_build_result (graph_spec , graph_metadata , release_version , graph_output_dir )
307306 return True
308307
309308 # Determine the release_version (semver) for a graph, deriving its deterministic build_version
@@ -943,6 +942,34 @@ def get_graph_metadata(self, graph_id: str, release_version: str):
943942 # load existing or create new metadata file
944943 return GraphMetadata (graph_id , graph_output_dir )
945944
945+ def _record_build_result (self ,
946+ graph_spec : GraphSpec ,
947+ graph_metadata : GraphMetadata ,
948+ release_version : str ,
949+ graph_output_dir : str ):
950+ self .build_results [graph_spec .graph_id ] = {
951+ 'graph_id' : graph_spec .graph_id ,
952+ 'release_version' : release_version ,
953+ 'build_version' : graph_spec .build_version ,
954+ 'graph_dir' : graph_output_dir ,
955+ 'build_status' : graph_metadata .get_build_status (),
956+ 'build_time' : graph_metadata .get_build_time (),
957+ }
958+
959+ # Write the build results from this invocation to graphs_dir/.build_results/<timestamp>.json.
960+ # Subsequent deployment stages read the most-recent file to discover what just built.
961+ # Returns the file path written, or None if nothing was built.
962+ def write_build_results (self ) -> str | None :
963+ if not self .build_results :
964+ return None
965+ results_dir = os .path .join (self .graphs_dir , '.build_results' )
966+ os .makedirs (results_dir , exist_ok = True )
967+ timestamp = datetime .datetime .now ().strftime ('%Y-%m-%dT%H%M%S' )
968+ results_path = os .path .join (results_dir , f'{ timestamp } .json' )
969+ with open (results_path , 'w' ) as f :
970+ json .dump (list (self .build_results .values ()), f , indent = 2 )
971+ return results_path
972+
946973
947974def _generate_inline_graph_spec (graph_id : str , sources_arg : str , output_format : str ) -> dict :
948975 source_ids = [s .strip () for s in sources_arg .split (',' ) if s .strip ()]
@@ -997,8 +1024,11 @@ def main():
9971024 graph_builder .build_graph (graph_spec )
9981025 else :
9991026 print (f'Invalid graph spec requested: { graph_id_arg } ' )
1000- for results_graph_id , results in graph_builder .build_results .items ():
1001- print (f'{ results_graph_id } \t { results ["version" ]} ' )
1027+ results_path = graph_builder .write_build_results ()
1028+ if results_path :
1029+ print (f'Build results written to { results_path } ' )
1030+ else :
1031+ print ('No graphs were built.' )
10021032
10031033
10041034if __name__ == '__main__' :
0 commit comments