@@ -610,16 +610,21 @@ def full_build(self):
610
610
def run (self , http : urllib3 .PoolManager ) -> bool :
611
611
"""Build and publish a Python doc, for a language, and a version."""
612
612
start_time = perf_counter ()
613
+ start_timestamp = dt .now (tz = timezone .utc ).replace (microsecond = 0 )
613
614
logging .info ("Running." )
614
615
try :
615
616
self .cpython_repo .switch (self .version .branch_or_tag )
616
617
if self .language .tag != "en" :
617
618
self .clone_translation ()
618
- if self .should_rebuild ():
619
+ if trigger_reason := self .should_rebuild ():
619
620
self .build_venv ()
620
621
self .build ()
621
622
self .copy_build_to_webroot (http )
622
- self .save_state (build_duration = perf_counter () - start_time )
623
+ self .save_state (
624
+ build_start = start_timestamp ,
625
+ build_duration = perf_counter () - start_time ,
626
+ trigger = trigger_reason ,
627
+ )
623
628
except Exception as err :
624
629
logging .exception ("Badly handled exception, human, please help." )
625
630
if sentry_sdk :
@@ -885,7 +890,7 @@ def should_rebuild(self):
885
890
state = self .load_state ()
886
891
if not state :
887
892
logging .info ("Should rebuild: no previous state found." )
888
- return True
893
+ return "no previous state"
889
894
cpython_sha = self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip ()
890
895
if self .language .tag != "en" :
891
896
translation_sha = self .translation_repo .run (
@@ -897,7 +902,7 @@ def should_rebuild(self):
897
902
state ["translation_sha" ],
898
903
translation_sha ,
899
904
)
900
- return True
905
+ return "new translations"
901
906
if cpython_sha != state ["cpython_sha" ]:
902
907
diff = self .cpython_repo .run (
903
908
"diff" , "--name-only" , state ["cpython_sha" ], cpython_sha
@@ -908,7 +913,7 @@ def should_rebuild(self):
908
913
state ["cpython_sha" ],
909
914
cpython_sha ,
910
915
)
911
- return True
916
+ return "Doc/ has changed"
912
917
logging .info ("Nothing changed, no rebuild needed." )
913
918
return False
914
919
@@ -921,7 +926,7 @@ def load_state(self) -> dict:
921
926
except (KeyError , FileNotFoundError ):
922
927
return {}
923
928
924
- def save_state (self , build_duration : float ):
929
+ def save_state (self , build_start : dt , build_duration : float , trigger : str ):
925
930
"""Save current CPython sha1 and current translation sha1.
926
931
927
932
Using this we can deduce if a rebuild is needed or not.
@@ -932,17 +937,24 @@ def save_state(self, build_duration: float):
932
937
except FileNotFoundError :
933
938
states = tomlkit .document ()
934
939
935
- state = {}
936
- state ["cpython_sha" ] = self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip ()
940
+ key = f"/{ self .language .tag } /{ self .version .name } /"
941
+ state = {
942
+ "last_build_start" : build_start ,
943
+ "last_build_duration" : round (build_duration , 0 ),
944
+ "triggered_by" : trigger ,
945
+ "cpython_sha" : self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip (),
946
+ }
937
947
if self .language .tag != "en" :
938
948
state ["translation_sha" ] = self .translation_repo .run (
939
949
"rev-parse" , "HEAD"
940
950
).stdout .strip ()
941
- state ["last_build" ] = dt .now (timezone .utc )
942
- state ["last_build_duration" ] = build_duration
943
- states [f"/{ self .language .tag } /{ self .version .name } /" ] = state
951
+ states [key ] = state
944
952
state_file .write_text (tomlkit .dumps (states ), encoding = "UTF-8" )
945
953
954
+ table = tomlkit .inline_table ()
955
+ table |= state
956
+ logging .info ("Saved new rebuild state for %s: %s" , key , table .as_string ())
957
+
946
958
947
959
def symlink (
948
960
www_root : Path ,
0 commit comments