From d46902210709a3ea8ce2b9353589f49c2f23bd7f Mon Sep 17 00:00:00 2001 From: wkoot <3715211+wkoot@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:01:16 +0200 Subject: [PATCH] Use new bump-my-version version to skip altering changelog for a rc --- release/pyproject.toml | 1 + release/release.py | 35 +++++++++++------------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/release/pyproject.toml b/release/pyproject.toml index 3dcc03d98c..355655f166 100644 --- a/release/pyproject.toml +++ b/release/pyproject.toml @@ -89,6 +89,7 @@ replace = "sonar.projectVersion={new_version}" filename = "../docs/src/changelog.md" search = "[Unreleased]" replace = "v{new_version} - {$RELEASE_DATE}" +include_bumps = ["pre_release_label"] # this is the only bump that produces a non-rc release [[tool.bumpversion.files]] filename = "../.env" diff --git a/release/release.py b/release/release.py index e75ce3e304..d717608dac 100755 --- a/release/release.py +++ b/release/release.py @@ -51,15 +51,9 @@ def parse_arguments() -> tuple[str, str, bool]: epilog=epilog, formatter_class=RawDescriptionHelpFormatter, ) - allowed_bumps_in_rc_mode = [ - "rc", - "rc-major", - "rc-minor", - "rc-patch", - "drop-rc", - ] # rc = release candidate - allowed_bumps = ["rc-patch", "rc-minor", "rc-major", "patch", "minor", "major"] - bumps = allowed_bumps_in_rc_mode if "rc" in current_version else allowed_bumps + bumps = ["patch", "minor", "major"] + if "rc" in current_version: + bumps += ["rc", "release"] parser.add_argument("bump", choices=bumps) parser.add_argument( "-c", @@ -71,7 +65,7 @@ def parse_arguments() -> tuple[str, str, bool]: return arguments.bump, current_version, arguments.check_preconditions_only -def check_preconditions(bump: str, current_version: str, rc: bool = False) -> None: +def check_preconditions(bump: str, current_version: str) -> None: """Check preconditions for version bump.""" messages = [] release_folder = get_release_folder() @@ -80,7 +74,7 @@ def check_preconditions(bump: str, current_version: str, rc: bool = False) -> No root = release_folder.parent messages.extend(failed_preconditions_repo(root)) messages.extend(failed_preconditions_changelog(bump, root)) - if not rc: + if bump == "release": # don't update the version overview for release candidates messages.extend(failed_preconditions_version_overview(current_version, root)) if messages: formatted_messages = "\n".join([f"- {message}" for message in messages]) @@ -115,7 +109,7 @@ def failed_preconditions_changelog(bump: str, root: pathlib.Path) -> list[str]: changelog_text = changelog_file.read() if "[Unreleased]" not in changelog_text: messages.append(f"The changelog ({changelog}) has no '[Unreleased]' header.") - if bump == "drop-rc" and "-rc." in changelog_text: + if bump == "release" and "-rc." in changelog_text: messages.append( f"The changelog ({changelog}) still contains release candidates; remove " "the release candidates and move their changes under the '[Unreleased]' header." @@ -130,8 +124,9 @@ def failed_preconditions_version_overview(current_version: str, root: pathlib.Pa version_overview_lines = version_overview_file.readlines() missing = f"The version overview ({version_overview}) does not contain" previous_line = "" + target_version = current_version.split("-rc.")[0] for line in version_overview_lines: - if line.startswith(f"| v{current_version} "): + if line.startswith(f"| v{target_version} "): if previous_line.startswith("| v"): today = utc_today().isoformat() release_date = previous_line.split(" | ")[1].strip() @@ -140,7 +135,7 @@ def failed_preconditions_version_overview(current_version: str, root: pathlib.Pa return [] # All good: current version, next version, and release date found return [f"{missing}) the new version."] previous_line = line - return [f"{missing} the current version ({current_version})."] + return [f"{missing} the target version ({target_version})."] def utc_today() -> datetime.date: @@ -154,25 +149,17 @@ def main() -> None: bump, current_version, check_preconditions_only = parse_arguments() # See https://github.com/callowayproject/bump-my-version?tab=readme-ov-file#add-support-for-pre-release-versions # for how bump-my-version deals with pre-release versions - create_rc = bump.startswith("rc") # needs to be True for case "rc", and "rc-*" - if bump.startswith("rc-"): - bump = bump.split("-", maxsplit=1)[1] # Create a patch, minor, or major release candidate - check_preconditions(bump, current_version, create_rc) + check_preconditions(bump, current_version) if check_preconditions_only: return cmd = ["bump-my-version", "bump"] - if bump == "drop-rc": + if bump == "release": cmd.append("pre_release_label") # Bump the pre-release label from "rc" to "final" (being optional and omitted) elif bump == "rc": cmd.append("pre_release_number") # Bump the release candidate number, when already on a -rc version else: cmd.append(bump) subprocess.run(cmd, check=True) # noqa: S603 - if create_rc: - changelog_path = get_release_folder().parent / "docs" / "src" / "changelog.md" - subprocess.run(("git", "checkout", "HEAD~1", "--", changelog_path), check=True) - subprocess.run(("git", "add", changelog_path), check=True) - subprocess.run(("git", "commit", "-m", "Reset changelog after producing release candidate"), check=True) subprocess.run(("git", "push", "--follow-tags"), check=True) # noqa: S603