Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept non-prerelease baseVersion (append -0.dev) #184

Merged
merged 3 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ charts:
# This gives you more control over development version tags
# and lets you ensure prerelease tags are always sorted in the right order.
# Only useful when publishing development releases.
baseVersion: 3.2.1-0.dev
# if this is not a prerelease version (no -suffix),
# the suffix `-0.dev` will be appended.
baseVersion: 3.2.1
# which is equivalent to
# baseVersion: 3.2.1-0.dev

# The git repo whose gh-pages contains the charts. This can be a local
# path such as "." as well but if matching <organization>/<repo> will be
Expand Down
13 changes: 8 additions & 5 deletions chartpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,17 +976,17 @@ def _check_base_version(base_version):
2. sort after the latest tag on the branch
"""

if "-" not in base_version:
# config version is a stable release,
# append default '-0.dev' so we always produce a prerelease
base_version = f"{base_version}-0.dev"
# check valid value (baseVersion must be semver prerelease)
match = _semver2.fullmatch(base_version)
if not match:
raise ValueError(
f"baseVersion: {base_version} must be a valid semver prerelease (e.g. 1.2.3-0.dev), but doesn't appear to be valid."
consideRatio marked this conversation as resolved.
Show resolved Hide resolved
)
base_version_groups = match.groupdict()
if not base_version_groups["prerelease"]:
raise ValueError(
f"baseVersion: {base_version} must be a valid semver prerelease (e.g. 1.2.3-0.dev), but is not a prerelease."
)

def _version_number(groups):
"""Return comparable semver"""
Expand Down Expand Up @@ -1020,6 +1020,9 @@ def _version_number(groups):
# tag not semver. ignore? Not really our problem.
_log(f"Latest tag {tag} does not appear to be a semver version")

# return base_version, in case it was modified
return base_version


class ActionStoreDeprecated(argparse.Action):
"""Used with argparse as a deprecation action."""
Expand Down Expand Up @@ -1183,7 +1186,7 @@ def main(argv=None):
# (e.g. forgetting to update after release)
base_version = chart.get("baseVersion", None)
if base_version:
_check_base_version(base_version)
base_version = _check_base_version(base_version)

if not args.list_images:
# update Chart.yaml with a version
Expand Down
35 changes: 18 additions & 17 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,35 +162,36 @@ def test__get_image_extra_build_command_options(git_repo):


@pytest.mark.parametrize(
"base_version, tag, n_commits, status",
"base_version, tag, n_commits, result",
[
# OK, normal state
("1.2.4-0.dev", "1.2.3", 10, "ok"),
("1.2.4-0.dev", "1.2.3", 10, "1.2.4-0.dev"),
# don't compare prereleases on the same tag
("1.2.3-0.dev", "1.2.3-alpha.1", 10, "ok"),
("1.2.3-0.dev", "1.2.3-alpha.1", 10, "1.2.3-0.dev"),
# invalid baseVersion (not semver)
("x.y.z", "1.2.3", 10, "valid semver prerelease"),
("x.y.z", "1.2.3", 10, ValueError("valid semver pre")),
# not prerelease baseVersion
("1.2.4", "1.2.3", 10, "valid semver prerelease"),
("1.2.4", "1.2.3", 10, "1.2.4-0.dev"),
# check comparison with tag
("1.2.2-0.dev", "1.2.3-alpha.1", 10, "is not greater"),
("1.2.3-0.dev", "1.2.3", 10, "is not greater"),
("1.2.3-0.dev", "2.0.0", 10, "is not greater"),
("1.2.3-0.dev", "1.2.4-alpha.1", 10, "is not greater"),
("1.2.2-0.dev", "1.2.3-alpha.1", 10, ValueError("is not greater")),
("1.2.3-0.dev", "1.2.3", 10, ValueError("is not greater")),
("1.2.3-0.dev", "2.0.0", 10, ValueError("is not greater")),
("1.2.3-0.dev", "1.2.4-alpha.1", 10, ValueError("is not greater")),
# don't check exactly on a tag
("1.2.3-0.dev", "2.0.0", 0, "ok"),
("1.2.3-0.dev", "2.0.0", 0, "1.2.3-0.dev"),
# ignore invalid semver tags
("1.2.3-0.dev", "x.y.z", 10, "ok"),
("1.2.3-0.dev", "x.y.z", 10, "1.2.3-0.dev"),
],
)
def test_check_base_version(base_version, tag, n_commits, status):
def test_check_base_version(base_version, tag, n_commits, result):
with mock.patch.object(
chartpress, "_get_latest_tag_and_count", lambda: (tag, n_commits)
):
if status == "ok":
chartpress._check_base_version(base_version)
else:
with pytest.raises(ValueError) as exc:
if isinstance(result, Exception):
with pytest.raises(result.__class__) as exc:
chartpress._check_base_version(base_version)
assert status in str(exc)
assert str(result) in str(exc)
assert base_version in str(exc)
else:
used_version = chartpress._check_base_version(base_version)
assert used_version == result