Skip to content

Commit aae6a3a

Browse files
committed
enforce that chart version is a prerelease tag, excluding set.by.chartpress
avoid creating weird versions from likely errors
1 parent 7dbdc2b commit aae6a3a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

chartpress.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ def build_images(
581581
The container build engine.
582582
platforms (list[str]):
583583
List of platforms to build for if not the same as the Docker host.
584+
base_version (str):
585+
The base version string (before '.git'), used when useChartVersion is True
586+
instead of the tag found via `git describe`.
584587
"""
585588
values_file_modifications = {}
586589
for name, options in images.items():
@@ -782,9 +785,22 @@ def build_chart(
782785
if use_chart_version:
783786
# avoid adding .git... to chart version multiple times!
784787
base_version = _trim_version_suffix(chart["version"])
785-
# TODO: trim -set.by.chartpress?
786-
# if base_version.endswith("-set.by.chartpress"):
787-
# base_version = base_version.rsplit("-", 1)[0]
788+
# check for default placeholder tags
789+
# avoid making weird combination of `1.0.0-set.by.chartpress.git.1.habc`
790+
if "set.by.chartpress" in chart["version"]:
791+
raise ValueError(
792+
f"Chart {chart_file} has placeholder version {chart['version']}, with `useChartVersion: true`."
793+
f"Set the version in the {chart_file} to a base pre-release tag,"
794+
" e.g. `1.0.0-0.dev` or `1.0.0-alpha.1` and run chartpress again."
795+
)
796+
797+
# require starting from a prerelease tag, to ensure correct ordering
798+
if "-" not in chart["version"]:
799+
raise ValueError(
800+
f"Chart {chart_file} has non-prerelease version {chart['version']} with `useChartVersion: true`"
801+
f"Set the version in the {chart_file} to a base pre-release tag,"
802+
" e.g. `1.0.0-0.dev` or `1.0.0-alpha.1` and run chartpress again."
803+
)
788804
else:
789805
base_version = None
790806
if reset:
@@ -1093,6 +1109,10 @@ def main(args=None):
10931109
)
10941110

10951111
if "images" in chart:
1112+
if use_chart_version:
1113+
base_version = _trim_version_suffix(chart_version)
1114+
else:
1115+
base_version = None
10961116
# build images
10971117
values_file_modifications = build_images(
10981118
prefix=args.image_prefix or chart.get("imagePrefix", ""),
@@ -1104,6 +1124,7 @@ def main(args=None):
11041124
force_push=args.force_push,
11051125
force_build=args.force_build,
11061126
skip_build=args.no_build or args.reset,
1127+
base_version=base_version,
11071128
long=args.long,
11081129
builder=args.builder,
11091130
platforms=args.platform,

0 commit comments

Comments
 (0)