@@ -657,10 +657,13 @@ def run(self) -> bool:
657
657
self .cpython_repo .switch (self .version .branch_or_tag )
658
658
if self .language .tag != "en" :
659
659
self .clone_translation ()
660
- self .build_venv ()
661
- self .build ()
662
- self .copy_build_to_webroot ()
663
- self .save_state (build_duration = perf_counter () - start_time )
660
+ if self .should_rebuild ():
661
+ self .build_venv ()
662
+ self .build ()
663
+ self .copy_build_to_webroot ()
664
+ self .save_state (build_duration = perf_counter () - start_time )
665
+ else :
666
+ logging .info ("Nothing changed." )
664
667
except Exception as err :
665
668
logging .exception ("Badly handled exception, human, please help." )
666
669
if sentry_sdk :
@@ -919,7 +922,35 @@ def copy_build_to_webroot(self):
919
922
purge (* [prefix + p for p in changed ])
920
923
logging .info ("Publishing done" )
921
924
922
- def save_state (self , build_duration ):
925
+ def should_rebuild (self ):
926
+ state = self .load_state ()
927
+ if not state :
928
+ return True
929
+ cpython_sha = self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip ()
930
+ if self .language .tag != "en" :
931
+ translation_sha = self .translation_repo .run (
932
+ "rev-parse" , "HEAD"
933
+ ).stdout .strip ()
934
+ if translation_sha != state ["translation_sha" ]:
935
+ return True
936
+ if cpython_sha != state ["cpython_sha" ]:
937
+ diff = self .cpython_repo .run (
938
+ "diff" , "--name-only" , state ["cpython_sha" ], cpython_sha
939
+ ).stdout
940
+ if "Doc/" in diff :
941
+ return True
942
+ return False
943
+
944
+ def load_state (self ) -> dict :
945
+ state_file = self .build_root / "state.toml"
946
+ try :
947
+ return tomlkit .loads (state_file .read_text (encoding = "UTF-8" ))[
948
+ f"/{ self .language .tag } /{ self .version .name } /"
949
+ ]
950
+ except KeyError :
951
+ return {}
952
+
953
+ def save_state (self , build_duration : float ):
923
954
"""Save current cpython sha1 and current translation sha1.
924
955
925
956
Using this we can deduce if a rebuild is needed or not.
@@ -938,11 +969,7 @@ def save_state(self, build_duration):
938
969
).stdout .strip ()
939
970
state ["last_build" ] = dt .now (timezone .utc )
940
971
state ["last_build_duration" ] = build_duration
941
-
942
- states .setdefault ("build" , {}).setdefault (self .language .tag , {})[
943
- self .version .name
944
- ] = state
945
-
972
+ states [f"/{ self .language .tag } /{ self .version .name } /" ] = state
946
973
state_file .write_text (tomlkit .dumps (states ), encoding = "UTF-8" )
947
974
948
975
0 commit comments