Skip to content

Commit 8cf9380

Browse files
committed
handle reset-version in the same place for both values of useChartVersion
1 parent 9b34972 commit 8cf9380

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

chartpress.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ def build_chart(
782782
reset=False,
783783
strict_version=False,
784784
use_chart_version=False,
785+
reset_version="0.0.1-set.by-chartpress",
785786
):
786787
"""
787788
Update Chart.yaml's version, using specified version or by constructing one.
@@ -807,15 +808,16 @@ def build_chart(
807808

808809
# decide a version string
809810
if version is None:
811+
# version unspecified, retrieve base version from Chart.yaml
810812
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!
812814
base_version = _trim_version_suffix(chart["version"])
813815
# check for default placeholder tags
814816
# 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"]:
816818
raise ValueError(
817819
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),"
819821
" e.g. `2.0.0-0.dev` or `2.0.0-alpha.1` and run chartpress again."
820822
)
821823

@@ -835,24 +837,35 @@ def build_chart(
835837
)
836838
else:
837839
base_version = None
840+
838841
if reset:
839842
# 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
841850
else:
842851
# derive the full version, with possible '.git...'
843852
version = _get_identifier_from_paths(
844853
*paths, long=long, base_version=base_version
845854
)
846855

847-
if not reset:
856+
if reset:
857+
_log(f"{chart_file}: resetting version to {version}")
858+
else:
848859
version = _fix_chart_version(version, strict=strict_version)
849860

850861
# update Chart.yaml
851-
if chart["version"] != version:
862+
if chart["version"] == version:
863+
_log(f"Leaving {chart_file} version unchanged: {version}")
864+
else:
852865
_log(f"Updating {chart_file}: version: {version}")
853866
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)
856869

857870
# return version
858871
return version
@@ -1124,10 +1137,6 @@ def main(args=None):
11241137
if args.tag:
11251138
# tag specified, use that version
11261139
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")
11311140

11321141
if not args.list_images:
11331142
# update Chart.yaml with a version
@@ -1139,6 +1148,7 @@ def main(args=None):
11391148
reset=args.reset,
11401149
strict_version=args.publish_chart,
11411150
use_chart_version=use_chart_version,
1151+
reset_version=chart.get("resetVersion", "0.0.1-set.by.chartpress"),
11421152
)
11431153

11441154
if "images" in chart:

0 commit comments

Comments
 (0)