@@ -778,17 +778,9 @@ def upgrade(
778778 "Commands may fail if they require authentication.[/]"
779779 )
780780
781- # Build the CI image for Python 3.10 first so that subsequent steps (e.g. uv lock
782- # updates inside the image) use an up-to-date environment.
783- console_print ("[info]Building CI image for Python 3.10 …[/]" )
784- run_command (
785- ["breeze" , "ci-image" , "build" , "--python" , "3.10" ],
786- check = False ,
787- env = command_env ,
788- )
789-
790- # Define all upgrade commands to run (all run with check=False to continue on errors)
791- upgrade_commands : list [tuple [str , str ]] = [
781+ # Define upgrade commands to run before building the CI image (all run with check=False
782+ # to continue on errors). These may update Dockerfiles and other build inputs.
783+ pre_image_commands : list [tuple [str , str ]] = [
792784 ("autoupdate" , "prek autoupdate --cooldown-days 4 --freeze" ),
793785 (
794786 "update-chart-dependencies" ,
@@ -798,20 +790,42 @@ def upgrade(
798790 "upgrade-important-versions" ,
799791 "prek --all-files --show-diff-on-failure --color always --verbose --stage manual upgrade-important-versions" ,
800792 ),
793+ ]
794+
795+ # Define upgrade commands to run after building the CI image (they run inside the image
796+ # and need an up-to-date environment).
797+ post_image_commands : list [tuple [str , str ]] = [
801798 (
802799 "update-uv-lock" ,
803800 "prek --all-files --show-diff-on-failure --color always --verbose update-uv-lock --stage manual" ,
804801 ),
805802 ]
803+
806804 step_enabled = {
807805 "autoupdate" : autoupdate ,
808806 "update-chart-dependencies" : update_chart_dependencies ,
809807 "upgrade-important-versions" : upgrade_important_versions ,
810808 "update-uv-lock" : update_uv_lock ,
811809 }
812810
813- # Execute enabled upgrade commands with the environment containing GitHub token
814- for step_name , command in upgrade_commands :
811+ # Execute pre-image upgrade commands (may update Dockerfiles)
812+ for step_name , command in pre_image_commands :
813+ if step_enabled [step_name ]:
814+ run_command (command .split (), check = False , env = command_env )
815+ else :
816+ console_print (f"[info]Skipping { step_name } (disabled).[/]" )
817+
818+ # Build the CI image for Python 3.10 after Dockerfiles have been updated so that
819+ # subsequent steps (e.g. uv lock updates inside the image) use an up-to-date environment.
820+ console_print ("[info]Building CI image for Python 3.10 …[/]" )
821+ run_command (
822+ ["breeze" , "ci-image" , "build" , "--python" , "3.10" ],
823+ check = False ,
824+ env = command_env ,
825+ )
826+
827+ # Execute post-image upgrade commands (run inside the freshly built image)
828+ for step_name , command in post_image_commands :
815829 if step_enabled [step_name ]:
816830 run_command (command .split (), check = False , env = command_env )
817831 else :
0 commit comments