Skip to content

Commit

Permalink
Fix handling of versions when dev versions are used (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jul 7, 2022
1 parent eb66cf8 commit face9d6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jupyter_releaser/actions/draft_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
os.chdir(curr_dir)


run_action("jupyter-releaser bump-version")
run_action("jupyter-releaser bump-version --use-changelog-version")

with make_group("Handle Check Release"):
if check_release:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def extract_current(changelog_path):
def extract_current_version(changelog_path):
"""Extract the current released version from the changelog"""
body = extract_current(changelog_path)
match = re.match(r"#+ ([\d.]+)", body.strip())
match = re.match(r"#+ ([\da-z.]+)", body.strip())
if not match:
raise ValueError("Could not find previous version")
return match.groups()[0]
16 changes: 14 additions & 2 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ def main(force):
),
]

use_changelog_version_options = [
click.option(
"--use-changelog-version",
envvar="RH_USE_CHANGELOG_VERSION",
is_flag=True,
help="Whether to use the changelog version if the current version is a dev version in version bump",
),
]

since_options = [
click.option(
"--since",
Expand Down Expand Up @@ -300,14 +309,17 @@ def prep_git(ref, branch, repo, auth, username, git_url):
@add_options(version_spec_options)
@add_options(version_cmd_options)
@add_options(changelog_path_options)
@add_options(use_changelog_version_options)
@add_options(python_packages_options)
@use_checkout_dir()
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
def bump_version(version_spec, version_cmd, changelog_path, use_changelog_version, python_packages):
"""Prep git and env variables and bump version"""
prev_dir = os.getcwd()
for python_package in [p.split(":")[0] for p in python_packages]:
os.chdir(python_package)
lib.bump_version(version_spec, version_cmd, changelog_path)
lib.bump_version(
version_spec, version_cmd, changelog_path, use_changelog_version=use_changelog_version
)
os.chdir(prev_dir)


Expand Down
14 changes: 11 additions & 3 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
from jupyter_releaser import changelog, npm, python, util


def bump_version(version_spec, version_cmd, changelog_path):
def bump_version(version_spec, version_cmd, changelog_path, use_changelog_version):
"""Bump the version and verify new version"""
util.bump_version(version_spec, version_cmd=version_cmd, changelog_path=changelog_path)
util.bump_version(
version_spec,
version_cmd=version_cmd,
changelog_path=changelog_path,
use_changelog_version=use_changelog_version,
)

version = util.get_version()

Expand Down Expand Up @@ -250,7 +255,10 @@ def draft_release(
# Bump to post version if given
if post_version_spec:
post_version = bump_version(
post_version_spec, version_cmd=version_cmd, changelog_path=changelog_path
post_version_spec,
version_cmd=version_cmd,
changelog_path=changelog_path,
use_changelog_version=False,
)
util.log(post_version_message.format(post_version=post_version))
util.run(f'git commit -a -m "Bump to {post_version}"')
Expand Down
8 changes: 8 additions & 0 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def test_bump_version(npm_package, runner):
assert version == "1.0.1-rc0"


def test_bump_version_use_changelog(npm_package, runner):
runner(["prep-git", "--git-url", npm_package])
runner(["bump-version", "--use-changelog-version"])
version = util.get_version()
assert version == "1.0.0"


def test_bump_version_bad_version(py_package, runner):
runner(["prep-git", "--git-url", py_package])
with pytest.raises(CalledProcessError):
Expand Down Expand Up @@ -173,6 +180,7 @@ def test_list_envvars(runner):
tag-message: RH_TAG_MESSAGE
twine-cmd: TWINE_COMMAND
twine-registry: TWINE_REGISTRY
use-changelog-version: RH_USE_CHANGELOG_VERSION
username: GITHUB_ACTOR
version-cmd: RH_VERSION_COMMAND
version-spec: RH_VERSION_SPEC
Expand Down
16 changes: 13 additions & 3 deletions jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,27 @@ def test_bump_version_reg(py_package):


def test_bump_version_dev(py_package):
changelog_path = py_package / "CHANGELOG.md"
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev1"
# Should get the version from the changelog
util.bump_version("next", changelog_path=py_package / "CHANGELOG.md")
util.bump_version("next", changelog_path=changelog_path)
assert util.get_version() == "0.0.2"
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("patch", changelog_path=py_package / "CHANGELOG.md")
assert util.get_version() == "0.0.2"
util.bump_version("patch", changelog_path=changelog_path, use_changelog_version=True)
assert util.get_version() == "0.0.1"
util.bump_version("1.0.0.dev0")
text = changelog_path.read_text(encoding="utf-8")
text = text.replace("0.0.1", "0.0.1a1")
changelog_path.write_text(text, encoding="utf-8")
util.bump_version("patch", changelog_path=changelog_path)
assert util.get_version() == "0.0.1a2"
util.bump_version("1.0.0.dev0")
util.bump_version("patch", changelog_path=changelog_path, use_changelog_version=True)
assert util.get_version() == "0.0.1a1"
util.bump_version("1.0.0.dev0")
util.bump_version("minor")
assert util.get_version() == "1.0.0"
Expand Down
12 changes: 10 additions & 2 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def create_release_commit(version, release_message=None, dist_dir="dist"):
return shas


def bump_version(version_spec, *, changelog_path="", version_cmd=""):
def bump_version(version_spec, *, changelog_path="", version_cmd="", use_changelog_version=False):
"""Bump the version"""
# Look for config files to determine version command if not given
if not version_cmd:
Expand Down Expand Up @@ -275,7 +275,15 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):

v = parse_version(extract_current_version(changelog_path))
assert isinstance(v, Version)
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
if use_changelog_version:
version_spec = v
elif v.is_prerelease:
assert v.pre
# Bump to the next prerelease.
version_spec = f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
else:
# Bump to the next micro.
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"

# Drop the dev portion and move to the minor release.
elif version_spec == "minor":
Expand Down

0 comments on commit face9d6

Please sign in to comment.