55import re
66import logging
77import subprocess
8- from typing import Dict , Any
8+ from typing import Dict , Any , Optional
99
1010logging .basicConfig (level = logging .INFO , format = "%(message)s" )
1111
@@ -71,15 +71,19 @@ def get_latest_module_release(repository: str, include_rc: bool = True) -> str:
7171 tags .sort (key = lambda v : (parse_version (v )[:3 ], parse_version (v )[3 ] or float ('inf' )))
7272 return tags [- 1 ]
7373
74- def bump_bundle_if_needed (versions_data : Dict [str , Any ], block : str ) -> None :
75- """Bump the bundle version for a block if it hasn't already been incremented vs mainline."""
76- current = versions_data [block ]["version" ]
74+ def get_mainline_bundle_version (block : str ) -> Optional [str ]:
75+ """Return the bundle version for a block on origin/mainline, or None if unavailable."""
7776 try :
7877 result = subprocess .check_output (['git' , 'show' , 'origin/mainline:versions.json' ], text = True )
79- mainline = json .loads (result )[ block ][ "version" ]
78+ return json .loads (result ). get ( block , {}). get ( "version" )
8079 except (subprocess .CalledProcessError , KeyError ):
81- mainline = None
82-
80+ return None
81+
82+ def bump_bundle_if_needed (versions_data : Dict [str , Any ], block : str ) -> None :
83+ """Bump the bundle version for a block if it hasn't already been incremented vs mainline."""
84+ current = versions_data [block ]["version" ]
85+ mainline = get_mainline_bundle_version (block )
86+
8387 if mainline is not None and mainline != current :
8488 logging .info (f"Bundle version { block } already incremented from { mainline } to { current } " )
8589 else :
@@ -115,25 +119,25 @@ def update_versions(versions_data: Dict[str, Any], component_name: str, new_vers
115119 stable_version = get_latest_module_release (repository , include_rc = False )
116120 versions_data [new_major_minor_release ]["modules" ][name ]["version" ] = stable_version
117121
118- # For backported valkey releases, always increment bundle version
119- if new_major_minor_release != latest :
122+ # Bump the bundle version only if it hasn't already been incremented
123+ mainline_bundle_version = get_mainline_bundle_version (new_major_minor_release )
124+ if mainline_bundle_version is not None and mainline_bundle_version != existing_bundle_version :
125+ logging .info (f"Valkey Bundle version { new_major_minor_release } already incremented from { mainline_bundle_version } to { existing_bundle_version } " )
126+ elif new_major_minor_release != latest :
127+ # Backported valkey release
120128 versions_data [new_major_minor_release ]["version" ] = bump_version (existing_bundle_version )
121- logging .info (f"Updated backported bundle version from { existing_bundle_version } to { versions_data [new_major_minor_release ]['version' ]} " )
129+ logging .info (f"Updated backported Valkey Bundle version from { existing_bundle_version } to { versions_data [new_major_minor_release ]['version' ]} " )
122130 else :
123- try :
124- subprocess .check_output (["git" , "ls-remote" , "--exit-code" , "--heads" , "origin" , "valkey-bundle-update" ], stderr = subprocess .DEVNULL )
125- logging .info ("There is an open PR for the branch valkey-bundle-update - bundle patch version won't be bumped." )
126- except subprocess .CalledProcessError :
127- bundle_major , bundle_minor , bundle_patch , bundle_rc = parse_version (existing_bundle_version )
128-
129- if rc is not None or bundle_rc is not None :
130- if rc is not None :
131- versions_data [new_major_minor_release ]["version" ] = f"{ bundle_major } .{ bundle_minor } .{ bundle_patch } -rc{ bundle_rc + 1 } "
132- else :
133- versions_data [new_major_minor_release ]["version" ] = f"{ bundle_major } .{ bundle_minor } .{ bundle_patch } "
131+ bundle_major , bundle_minor , bundle_patch , bundle_rc = parse_version (existing_bundle_version )
132+
133+ if rc is not None or bundle_rc is not None :
134+ if rc is not None :
135+ versions_data [new_major_minor_release ]["version" ] = f"{ bundle_major } .{ bundle_minor } .{ bundle_patch } -rc{ (bundle_rc or 0 ) + 1 } "
134136 else :
135- versions_data [new_major_minor_release ]["version" ] = bump_version (existing_bundle_version )
136- logging .info ("There is no open PR for the branch valkey-bundle-update — bumping bundle patch version." )
137+ versions_data [new_major_minor_release ]["version" ] = f"{ bundle_major } .{ bundle_minor } .{ bundle_patch } "
138+ else :
139+ versions_data [new_major_minor_release ]["version" ] = bump_version (existing_bundle_version )
140+ logging .info (f"Bumped Valkey Bundle version { new_major_minor_release } from { existing_bundle_version } to { versions_data [new_major_minor_release ]['version' ]} " )
137141 else :
138142 # New major/minor version
139143 known_modules = get_known_modules_from_versions (versions_data )
@@ -179,6 +183,8 @@ def update_versions(versions_data: Dict[str, Any], component_name: str, new_vers
179183 )
180184 sys .exit (0 )
181185
186+ module_updated = False
187+
182188 if patch > 0 :
183189 # For patch releases we will update all version entries with the same major.minor version as the module patch we just released
184190 for version_block in versions_data .keys ():
@@ -187,23 +193,24 @@ def update_versions(versions_data: Dict[str, Any], component_name: str, new_vers
187193 current_module_version = versions_data [version_block ]["modules" ][module_key ]["version" ]
188194 current_major , current_minor , _ , _ = parse_version (current_module_version )
189195 current_major_minor = f"{ current_major } .{ current_minor } "
190-
196+
191197 if current_major_minor == new_major_minor_release :
192198 versions_data [version_block ]["modules" ][module_key ]["version" ] = new_version
193199 logging .info (f"Patch release: Updated { module_key } to { new_version } in Bundle version { version_block } " )
194-
195- if version_block != latest :
200+
201+ if version_block == latest :
202+ module_updated = True
203+ else :
196204 bump_bundle_if_needed (versions_data , version_block )
197205 else :
198206 # For major or minor releases we will only update latest version entry
199207 versions_data [latest ]["modules" ][module_key ] = {"version" : new_version }
208+ module_updated = True
200209
201- try :
202- subprocess .check_output (["git" , "ls-remote" , "--exit-code" , "--heads" , "origin" , "valkey-bundle-update" ], stderr = subprocess .DEVNULL )
203- logging .info ("There is an open PR for the branch valkey-bundle-update - bundle patch version won't be bumped." )
204- except subprocess .CalledProcessError :
210+ # Only bump the latest bundle if the module for the latest block actually changed.
211+ if module_updated :
205212 bump_bundle_if_needed (versions_data , latest )
206-
213+
207214 return versions_data
208215
209216if __name__ == "__main__" :
0 commit comments