Skip to content

Commit 0d42a7a

Browse files
committed
Fix for major version jumps
1 parent a6cd877 commit 0d42a7a

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

ci/scripts/autobump-dependencies.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,27 @@ 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 version jump adjustment to the zero version
375+
if int(latest_major) > int(current_major):
376+
comparison_current = f"{current_major}.{current_minor}.0"
377+
378+
return comparison_current, comparison_latest
379+
359380
def get_release_notes(self) -> str:
360381
current_version = self.current_version
361382
latest_version = self.latest_release.version
@@ -381,15 +402,25 @@ def get_release_notes(self) -> str:
381402
```
382403
""")
383404

405+
# Get normalized versions for comparison
406+
comparison_current, comparison_latest = self._get_comparison_versions(current_version, latest_version)
407+
384408
startCopy = False
385409
for line in file:
386-
if (line.endswith(str(latest_version)+"\n")): # Start copying from latest version head
410+
if (line.endswith(comparison_latest+"\n")): # Start copying from latest version head
387411
startCopy = True
388-
if (line.endswith(str(current_version)+"\n")): # Stop when reaching current version
412+
if (line.endswith(comparison_current+"\n")): # Stop when reaching current version
389413
break
390414
if not startCopy:
391415
continue
392416
releaseNote += line
417+
# PR body length is limited by 65536 characters, truncating the change log to 60000 to avoid a validation error
418+
releaseNoteLimit = 60000
419+
if len(releaseNote) > releaseNoteLimit:
420+
releaseNote = releaseNote[:releaseNoteLimit] + textwrap.dedent(f"""
421+
422+
Change log was trimmed to {releaseNoteLimit} characters. Please see the changelog file for the full change log.
423+
""")
393424

394425
releaseNote += textwrap.dedent(f"""
395426
```

0 commit comments

Comments
 (0)