diff --git a/jupyter_releaser/actions/draft_release.py b/jupyter_releaser/actions/draft_release.py index 5cfd58e6..401b001e 100644 --- a/jupyter_releaser/actions/draft_release.py +++ b/jupyter_releaser/actions/draft_release.py @@ -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: diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index 318952bb..bcb7e9bf 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -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] diff --git a/jupyter_releaser/cli.py b/jupyter_releaser/cli.py index 1bc52c3a..bca3645a 100644 --- a/jupyter_releaser/cli.py +++ b/jupyter_releaser/cli.py @@ -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", @@ -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) diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 8c373d67..4afae8c1 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -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() @@ -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}"') diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index c5757705..4da9c4aa 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -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): @@ -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 diff --git a/jupyter_releaser/tests/test_functions.py b/jupyter_releaser/tests/test_functions.py index eee252ac..3c88fa19 100644 --- a/jupyter_releaser/tests/test_functions.py +++ b/jupyter_releaser/tests/test_functions.py @@ -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" diff --git a/jupyter_releaser/util.py b/jupyter_releaser/util.py index 4d0a668c..3576b392 100644 --- a/jupyter_releaser/util.py +++ b/jupyter_releaser/util.py @@ -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: @@ -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":