@@ -782,6 +782,7 @@ def build_chart(
782
782
reset = False ,
783
783
strict_version = False ,
784
784
use_chart_version = False ,
785
+ reset_version = "0.0.1-set.by-chartpress" ,
785
786
):
786
787
"""
787
788
Update Chart.yaml's version, using specified version or by constructing one.
@@ -807,15 +808,16 @@ def build_chart(
807
808
808
809
# decide a version string
809
810
if version is None :
811
+ # version unspecified, retrieve base version from Chart.yaml
810
812
if use_chart_version :
811
- # avoid adding .git... to chart version multiple times!
813
+ # extract base version to avoid adding .git... to chart version multiple times!
812
814
base_version = _trim_version_suffix (chart ["version" ])
813
815
# check for default placeholder tags
814
816
# avoid making weird combination of `1.0.0-set.by.chartpress.git.1.habc`
815
- if "set.by.chartpress" in chart ["version" ]:
817
+ if reset_version . split ( "-" , 1 )[ 1 ] in chart ["version" ]:
816
818
raise ValueError (
817
819
f"Chart { chart_file } has placeholder version { chart ['version' ]} , with `useChartVersion: true`."
818
- f" Set the version in the { chart_file } to a base pre-release tag (your _next_ release),"
820
+ f" Set the version in { chart_file } to a base pre-release tag (your _next_ release),"
819
821
" e.g. `2.0.0-0.dev` or `2.0.0-alpha.1` and run chartpress again."
820
822
)
821
823
@@ -835,24 +837,35 @@ def build_chart(
835
837
)
836
838
else :
837
839
base_version = None
840
+
838
841
if reset :
839
842
# resetting, use the base version without '.git...'
840
- version = base_version
843
+ # This path taken by `chartpress --reset` with no tag
844
+ if use_chart_version :
845
+ # get reset version from Chart.yaml
846
+ version = base_version
847
+ else :
848
+ # reset version comes from resetVersion chart config
849
+ version = reset_version
841
850
else :
842
851
# derive the full version, with possible '.git...'
843
852
version = _get_identifier_from_paths (
844
853
* paths , long = long , base_version = base_version
845
854
)
846
855
847
- if not reset :
856
+ if reset :
857
+ _log (f"{ chart_file } : resetting version to { version } " )
858
+ else :
848
859
version = _fix_chart_version (version , strict = strict_version )
849
860
850
861
# update Chart.yaml
851
- if chart ["version" ] != version :
862
+ if chart ["version" ] == version :
863
+ _log (f"Leaving { chart_file } version unchanged: { version } " )
864
+ else :
852
865
_log (f"Updating { chart_file } : version: { version } " )
853
866
chart ["version" ] = version
854
- with open (chart_file , "w" ) as f :
855
- yaml .dump (chart , f )
867
+ with open (chart_file , "w" ) as f :
868
+ yaml .dump (chart , f )
856
869
857
870
# return version
858
871
return version
@@ -1124,10 +1137,6 @@ def main(args=None):
1124
1137
if args .tag :
1125
1138
# tag specified, use that version
1126
1139
forced_version = args .tag
1127
- elif args .reset and not use_chart_version :
1128
- # resetting, get version from chartpress.yaml,
1129
- # ignoring current version in Chart.yaml
1130
- forced_version = chart .get ("resetVersion" , "0.0.1-set.by.chartpress" )
1131
1140
1132
1141
if not args .list_images :
1133
1142
# update Chart.yaml with a version
@@ -1139,6 +1148,7 @@ def main(args=None):
1139
1148
reset = args .reset ,
1140
1149
strict_version = args .publish_chart ,
1141
1150
use_chart_version = use_chart_version ,
1151
+ reset_version = chart .get ("resetVersion" , "0.0.1-set.by.chartpress" ),
1142
1152
)
1143
1153
1144
1154
if "images" in chart :
0 commit comments