66from typing import TYPE_CHECKING , Any
77
88from invoke import Context , task
9+ from packaging .version import Version
910
1011from tasks .shared import init_yaml_obj
1112from tasks .utils import (
@@ -101,7 +102,7 @@ def update_helm_chart(context: Context, chart_repo: str | None = "helm/") -> Non
101102 print (" - [release] Update Helm chart" )
102103
103104 # Get the app version directly from pyproject.toml
104- app_version = get_version_from_pyproject () # Returns a string like '1.1.0a1'
105+ app_version = Version ( get_version_from_pyproject () ) # Returns a string like '1.1.0a1'
105106
106107 for chart in ["infrahub" , "infrahub-enterprise" ]:
107108 # Initialize YAML and load the Chart.yaml file
@@ -112,43 +113,45 @@ def update_helm_chart(context: Context, chart_repo: str | None = "helm/") -> Non
112113 if "appVersion" not in chart_yaml :
113114 raise ValueError (f"appVersion not found in { str (chart_path )} ; no updates made." )
114115
115- old_app_version = chart_yaml .get ("appVersion" , "" )
116+ old_app_version = Version ( chart_yaml .get ("appVersion" , "" ) )
116117 if old_app_version == app_version :
117118 print (
118119 f"{ str (chart_path )} updates not required, `appVersion` of { old_app_version } matches current from `pyproject.toml`"
119120 )
120121 return
121122
122123 # Handle Helm chart version increment
123- old_helm_version = chart_yaml .get ("version" , "" )
124+ old_helm_version = Version ( chart_yaml .get ("version" , "" ) )
124125 if not old_helm_version :
125126 raise ValueError (f"Helm chart `version` not found in { str (chart_path )} ; no updates made." )
126127
127- # Split the Helm chart version into components for increment logic
128- major , minor , patch = map (int , old_helm_version .split ("." ))
129- new_helm_version = f"{ major } .{ minor } .{ patch } "
128+ new_helm_version = old_helm_version
130129
131130 # Determine the appropriate increment
132131 try :
133- if app_version > old_app_version :
134- if int ( app_version .split ( "." )[ 0 ]) > int ( old_app_version .split ( "." )[ 0 ]) :
135- new_helm_version = f"{ major + 1 } .0.0"
136- elif int ( app_version .split ( "." )[ 1 ]) > int ( old_app_version .split ( "." )[ 1 ]) :
137- new_helm_version = f"{ major } .{ minor + 1 } .0"
138- elif int ( app_version .split ( "." )[ 2 ]. split ( "a" )[ 0 ]) > int (
139- old_app_version . split ( "." )[ 2 ]. split ( "a" )[ 0 ]
140- ): # For alpha, beta handling
141- new_helm_version = f" { major } . { minor } . { patch + 1 } "
132+ if not app_version . is_prerelease and app_version > old_app_version :
133+ if app_version .major > old_app_version .major :
134+ new_helm_version = Version ( f"{ new_helm_version . major + 1 } .0.0" )
135+ elif app_version .minor > old_app_version .minor :
136+ new_helm_version = Version ( f"{ new_helm_version . major } .{ new_helm_version . minor + 1 } .0" )
137+ elif app_version .micro > old_app_version . micro :
138+ new_helm_version = Version (
139+ f" { new_helm_version . major } . { new_helm_version . minor } . { new_helm_version . micro + 1 } "
140+ )
142141 except Exception :
143142 # Fallback in case app_version has non-standard format for Helm comparison
144143 print (f"Warning: Unable to strictly compare versions, using default Helm chart version: { new_helm_version } " )
145144
145+ # Convert Version to str before passing to yaml
146+ app_version = str (app_version )
147+ new_helm_version = str (new_helm_version )
148+
146149 # Update the YAML
147150 chart_yaml ["appVersion" ] = app_version
148151 chart_yaml ["version" ] = new_helm_version
149152
150153 if chart == "infrahub" :
151- dependency_version = new_helm_version
154+ dependency_version = str ( new_helm_version )
152155
153156 yaml_values : YAML = init_yaml_obj ()
154157 values_path = Path (chart_repo ) / "charts" / Path (chart ) / "values.yaml"
0 commit comments