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

Allow the tag format customization #536

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 19 additions & 8 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ def main(force):
),
]

tag_format_options: t.Any = [
click.option(
"--tag-format",
envvar="RH_TAG_FORMAT",
default="v{version}",
help="The format to use for the release tag",
)
]


def add_options(options):
"""Add extracted common options to a click command"""
Expand Down Expand Up @@ -358,13 +367,14 @@ def prep_git(ref, branch, repo, auth, username, git_url):
@add_options(version_cmd_options)
@add_options(changelog_path_options)
@add_options(python_packages_options)
@add_options(tag_format_options)
@use_checkout_dir()
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
def bump_version(version_spec, version_cmd, changelog_path, python_packages, tag_format):
"""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, tag_format)
os.chdir(prev_dir)


Expand Down Expand Up @@ -406,6 +416,7 @@ def build_changelog(
@add_options(changelog_path_options)
@add_options(dry_run_options)
@add_options(post_version_spec_options)
@add_options(tag_format_options)
@use_checkout_dir()
def draft_changelog(
version_spec,
Expand All @@ -419,6 +430,7 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
tag_format,
):
"""Create a changelog entry PR"""
lib.draft_changelog(
Expand All @@ -433,6 +445,7 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
tag_format,
)


Expand Down Expand Up @@ -511,12 +524,7 @@ def check_npm(dist_dir, npm_install_options):
default="Publish {version}",
help="The message to use for the release commit",
)
@click.option(
"--tag-format",
envvar="RH_TAG_FORMAT",
default="v{version}",
help="The format to use for the release tag",
)
@add_options(tag_format_options)
@click.option(
"--tag-message",
envvar="RH_TAG_MESSAGE",
Expand Down Expand Up @@ -544,6 +552,7 @@ def tag_release(dist_dir, release_message, tag_format, tag_message, no_git_tag_w
@add_options(release_url_options)
@add_options(post_version_spec_options)
@click.argument("assets", nargs=-1)
@add_options(tag_format_options)
@use_checkout_dir()
def populate_release(
ref,
Expand All @@ -558,6 +567,7 @@ def populate_release(
post_version_spec,
post_version_message,
assets,
tag_format,
):
"""Populate a release."""
lib.populate_release(
Expand All @@ -573,6 +583,7 @@ def populate_release(
post_version_spec,
post_version_message,
assets,
tag_format,
)


Expand Down
18 changes: 12 additions & 6 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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, tag_format):
"""Bump the version and verify new version"""
util.bump_version(version_spec, version_cmd=version_cmd, changelog_path=changelog_path)

Expand All @@ -36,7 +36,7 @@ def bump_version(version_spec, version_cmd, changelog_path):
raise ValueError(msg)

# Bail if tag already exists
tag_name = f"v{version}"
tag_name = tag_format.format(version=version)
if tag_name in util.run("git --no-pager tag", quiet=True).splitlines():
msg = f"Tag {tag_name} already exists!"
msg += " To delete run: `git push --delete origin {tag_name}`"
Expand All @@ -57,12 +57,14 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
tag_format,
):
"""Create a changelog entry PR"""
repo = repo or util.get_repo()
branch = branch or util.get_branch()
version = util.get_version()
prerelease = util.is_prerelease(version)
tag_name = tag_format.format(version=version)

current_sha = util.run("git rev-parse HEAD")

Expand All @@ -73,8 +75,8 @@ def draft_changelog(
util.log(npm_versions)

tags = util.run("git --no-pager tag", quiet=True)
if f"v{version}" in tags.splitlines():
msg = f"Tag v{version} already exists"
if tag_name in tags.splitlines():
msg = f"Tag {tag_name} already exists"
raise ValueError(msg)

current = changelog.extract_current(changelog_path)
Expand Down Expand Up @@ -110,7 +112,7 @@ def draft_changelog(
json.dump(data, fid)

release = gh.create_release(
f"v{version}", branch, f"v{version}", current, True, prerelease, files=[metadata_path]
tag_name, branch, tag_name, current, True, prerelease, files=[metadata_path]
)

# Remove draft releases over a day old
Expand Down Expand Up @@ -209,6 +211,7 @@ def populate_release(
post_version_spec,
post_version_message,
assets,
tag_format,
):
"""Populate release assets and push tags and commits"""
branch = branch or util.get_branch()
Expand All @@ -221,7 +224,10 @@ def populate_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,
tag_format=tag_format,
)
util.log(post_version_message.format(post_version=post_version))
util.run(f'git commit -a -m "Bump to {post_version}"')
Expand Down
10 changes: 10 additions & 0 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ def test_bump_version_tag_exists(py_package, runner):
runner(["bump-version", "--version-spec", "1.0.1"], env=dict(GITHUB_ACTIONS=""))


def test_bump_version_custom_tag_exists(py_package, runner):
runner(["prep-git", "--git-url", py_package])
run("git tag rev1.0.1", cwd=util.CHECKOUT_NAME)
with pytest.raises(ValueError):
runner(
["bump-version", "--version-spec", "1.0.1"],
env=dict(GITHUB_ACTIONS="", RH_TAG_FORMAT=r"rev{version}"),
)


def test_list_envvars(runner):
result = runner(["list-envvars"])
assert (
Expand Down
Loading