77
88from lib .base_logger import logger
99from scripts .release .build .build_info import *
10+ from scripts .release .helm_registry_login import BUILD_SCENARIO_RELEASE
1011
1112CHART_DIR = "helm_chart"
1213
@@ -28,17 +29,14 @@ def run_command(command: list[str]):
2829
2930# update_chart_and_get_metadata updates the helm chart's Chart.yaml and sets the version
3031# to either evg patch id or commit which is set in OPERATOR_VERSION.
31- def update_chart_and_get_metadata (chart_dir : str ) -> tuple [str , str ]:
32+ def update_chart_and_get_metadata (chart_dir : str , build_scenario ) -> tuple [str , str ]:
3233 chart_path = os .path .join (chart_dir , "Chart.yaml" )
33- version_id = os .environ .get ("OPERATOR_VERSION" )
34- if not version_id :
34+ version = os .environ .get ("OPERATOR_VERSION" )
35+ if not version :
3536 raise ValueError (
3637 "Error: Environment variable 'OPERATOR_VERSION' must be set to determine the chart version to publish."
3738 )
3839
39- new_version = f"0.0.0+{ version_id } "
40- logger .info (f"New helm chart version will be: { new_version } " )
41-
4240 if not os .path .exists (chart_path ):
4341 raise FileNotFoundError (
4442 f"Error: Chart.yaml not found in directory '{ chart_dir } '. "
@@ -52,7 +50,17 @@ def update_chart_and_get_metadata(chart_dir: str) -> tuple[str, str]:
5250 chart_name = data .get ("name" )
5351 if not chart_name :
5452 raise ValueError ("Chart.yaml is missing required 'name' field." )
53+ except Exception as e :
54+ raise Exception (f"Unable to load Chart.yaml from dir { chart_path } " )
55+
56+ # if build_scenario is release, the chart.yaml would already have correct chart version
57+ if build_scenario == BUILD_SCENARIO_RELEASE :
58+ return chart_name , version
5559
60+ new_version = f"0.0.0+{ version } "
61+ logger .info (f"New helm chart version will be: { new_version } " )
62+
63+ try :
5664 data ["version" ] = new_version
5765
5866 with open (chart_path , "w" ) as f :
@@ -79,10 +87,10 @@ def get_oci_registry(chart_info: HelmChartInfo) -> str:
7987 return oci_registry
8088
8189
82- def publish_helm_chart (chart_info : HelmChartInfo ):
90+ def publish_helm_chart (chart_info : HelmChartInfo , build_scenario ):
8391 try :
8492 oci_registry = get_oci_registry (chart_info )
85- chart_name , chart_version = update_chart_and_get_metadata (CHART_DIR )
93+ chart_name , chart_version = update_chart_and_get_metadata (CHART_DIR , build_scenario )
8694 tgz_filename = f"{ chart_name } -{ chart_version } .tgz"
8795
8896 logger .info (f"Packaging chart: { chart_name } with Version: { chart_version } " )
@@ -108,7 +116,7 @@ def main():
108116 build_scenario = args .build_scenario
109117 build_info = load_build_info (build_scenario )
110118
111- return publish_helm_chart (build_info .helm_charts ["mongodb-kubernetes" ])
119+ return publish_helm_chart (build_info .helm_charts ["mongodb-kubernetes" ], build_scenario )
112120
113121
114122if __name__ == "__main__" :
0 commit comments