Skip to content

Commit

Permalink
Use new bump-my-version version to skip altering changelog for a rc
Browse files Browse the repository at this point in the history
  • Loading branch information
wkoot committed Jun 14, 2024
1 parent 423650c commit 2f62269
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
3 changes: 2 additions & 1 deletion release/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "release"
version = "5.13.0"
dependencies = [
"bump-my-version==0.22.0.post197.dev9",
"bump-my-version==0.23.0",
"gitpython==3.1.43",
]

Expand Down Expand Up @@ -50,6 +50,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"
Expand Down
29 changes: 11 additions & 18 deletions release/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def parse_arguments() -> tuple[str, str, bool]:
- the changelog contains no release candidates
- the new release has been added to the version overview"""
parser = ArgumentParser(description=description, 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", "--check-preconditions-only", action="store_true", help="only check the preconditions and then exit"
Expand All @@ -56,7 +56,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()
Expand All @@ -65,7 +65,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])
Expand Down Expand Up @@ -100,7 +100,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."
Expand All @@ -115,8 +115,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 = datetime.date.today().isoformat()
release_date = previous_line.split(" | ")[1].strip()
Expand All @@ -125,7 +126,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 main() -> None:
Expand All @@ -134,25 +135,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)
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)


Expand Down
6 changes: 3 additions & 3 deletions release/requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ build==1.2.1 \
--hash=sha256:526263f4870c26f26c433545579475377b2b7588b6f1eac76a001e873ae3e19d \
--hash=sha256:75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4
# via pip-tools
bump-my-version==0.22.0.post197.dev9 \
--hash=sha256:06730e001feca266dbbab1b273497eab4fd9bba677ad21c2441b04a9ed2aa085 \
--hash=sha256:546940433eb670955b6134e8c2b1def02678e804f4291144cdffc3342750366f
bump-my-version==0.23.0 \
--hash=sha256:984fcc5de3f6f67dd52bb4cfcddebad8e9725c0eb48b38d1fafb7ab19e15e527 \
--hash=sha256:c3017220bb70cade2cd865ac438fc8f9039ba65a4212fd37730197f512e10315
# via release (pyproject.toml)
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
Expand Down
6 changes: 3 additions & 3 deletions release/requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ bracex==2.4 \
--hash=sha256:a27eaf1df42cf561fed58b7a8f3fdf129d1ea16a81e1fadd1d17989bc6384beb \
--hash=sha256:efdc71eff95eaff5e0f8cfebe7d01adf2c8637c8c92edaf63ef348c241a82418
# via wcmatch
bump-my-version==0.22.0.post197.dev9 \
--hash=sha256:06730e001feca266dbbab1b273497eab4fd9bba677ad21c2441b04a9ed2aa085 \
--hash=sha256:546940433eb670955b6134e8c2b1def02678e804f4291144cdffc3342750366f
bump-my-version==0.23.0 \
--hash=sha256:984fcc5de3f6f67dd52bb4cfcddebad8e9725c0eb48b38d1fafb7ab19e15e527 \
--hash=sha256:c3017220bb70cade2cd865ac438fc8f9039ba65a4212fd37730197f512e10315
# via release (pyproject.toml)
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
Expand Down

0 comments on commit 2f62269

Please sign in to comment.