Skip to content

Commit 8b20b89

Browse files
committed
Version class is comparison aware, remove unnecessary split & conversions
1 parent 8c3274d commit 8b20b89

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

ci/scripts/autobump-dependencies.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -356,33 +356,26 @@ def fetch_latest_release(self) -> Release:
356356
version.parse(latest_version),
357357
)
358358

359-
# Parse, validate and split version into parts
360-
def _parse_and_split_version(self, version):
361-
version_parts = version.split('.')
362-
if len(version_parts) < 3:
363-
raise Exception(f"Expected version with 3 semver segments (major.minor.patch), got less: {version}.")
364-
return version_parts[0], version_parts[1], version_parts[2]
365-
366-
# Returns normalized versions for changelog comparison
367-
def _get_comparison_versions(self, current_version, latest_version):
368-
comparison_current = str(current_version)
369-
comparison_latest = str(latest_version)
370-
371-
current_major, current_minor, current_patch = self._parse_and_split_version(comparison_current)
372-
latest_major, latest_minor, latest_patch = self._parse_and_split_version(comparison_latest)
373-
374-
# Major and minor version jump adjustment to the zero version
375-
if int(latest_major) > int(current_major) or int(latest_minor) > int(current_minor):
376-
comparison_current = f"{current_major}.{current_minor}.0"
359+
def _get_comparison_versions(self):
360+
""" HAProxy tracks each minor version in a dedicated repository and the changelog in each repository only ever
361+
observes the .0 of previous minor versions as they are split off into a dedicated repository at that point.
362+
To make a comparison across major and minor versions we need to compare against the .0 of the previous minor
363+
version, this helper converts the comparison base accordingly.
364+
"""
365+
current_version = self.current_version
366+
latest_version = self.latest_release.version
367+
if latest_version.major > current_version.major or latest_version.minor > current_version.minor:
368+
current_version = version.Version(f"{current_version.major}.{current_version.minor}.0")
377369

378-
return comparison_current, comparison_latest
370+
return str(current_version), str(latest_version)
379371

380372
def get_release_notes(self) -> str:
381-
current_version = self.current_version
382-
latest_version = self.latest_release.version
383373

384-
if (current_version == latest_version):
385-
raise Exception(f"""Changelog requested but current and latest versions are the same: {current_version}""")
374+
if self.current_version == self.latest_release.version:
375+
raise Exception(f"""Changelog requested for identical current and latest versions: {self.current_version}""")
376+
377+
# Set patch part of the current version to 0 for minor and major version bumps
378+
current_version, latest_version = self._get_comparison_versions()
386379

387380
releaseNote = textwrap.dedent(f"""
388381
[Changelog for HAProxy {latest_version}](https://www.haproxy.org/download/{HAPROXY_VERSION}/src/CHANGELOG).
@@ -402,14 +395,11 @@ def get_release_notes(self) -> str:
402395
```
403396
""")
404397

405-
# Get normalized versions for comparison
406-
comparison_current, comparison_latest = self._get_comparison_versions(current_version, latest_version)
407-
408398
startCopy = False
409399
for line in file:
410-
if (line.endswith(comparison_latest+"\n")): # Start copying from latest version head
400+
if (line.endswith(latest_version+"\n")): # Start copying from latest version head
411401
startCopy = True
412-
if (line.endswith(comparison_current+"\n")): # Stop when reaching current version
402+
if (line.endswith(current_version+"\n")): # Stop when reaching current version
413403
break
414404
if not startCopy:
415405
continue

0 commit comments

Comments
 (0)