-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix changelog generation #3856
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
Merged
Merged
Fix changelog generation #3856
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "roo-cline": patch | ||
| --- | ||
|
|
||
| Fix changelog generation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """ | ||
| This script updates a specific version's release notes section in CHANGELOG.md with new content | ||
| or reformats existing content. | ||
|
|
||
| The script: | ||
| 1. Takes a version number, changelog path, and optionally new content as input from environment variables | ||
| 2. Finds the section in the changelog for the specified version | ||
| 3. Either: | ||
| a) Replaces the content with new content if provided, or | ||
| b) Reformats existing content by: | ||
| - Removing the first two lines of the changeset format | ||
| - Ensuring version numbers are wrapped in square brackets | ||
| 4. Writes the updated changelog back to the file | ||
|
|
||
| Environment Variables: | ||
| CHANGELOG_PATH: Path to the changelog file (defaults to 'CHANGELOG.md') | ||
| VERSION: The version number to update/format | ||
| PREV_VERSION: The previous version number (used to locate section boundaries) | ||
| NEW_CONTENT: Optional new content to insert for this version | ||
| """ | ||
|
|
||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
|
|
||
| CHANGELOG_PATH = os.environ.get("CHANGELOG_PATH", "CHANGELOG.md") | ||
| VERSION = os.environ["VERSION"] | ||
| PREV_VERSION = os.environ.get("PREV_VERSION", "") | ||
| NEW_CONTENT = os.environ.get("NEW_CONTENT", "") | ||
|
|
||
|
|
||
| def overwrite_changelog_section(changelog_text: str, new_content: str): | ||
| # Find the section for the specified version | ||
| version_pattern = f"## {VERSION}\n" | ||
| prev_version_pattern = f"## [{PREV_VERSION}]\n" | ||
| print(f"latest version: {VERSION}") | ||
| print(f"prev_version: {PREV_VERSION}") | ||
|
|
||
| notes_start_index = changelog_text.find(version_pattern) + len(version_pattern) | ||
| notes_end_index = ( | ||
| changelog_text.find(prev_version_pattern, notes_start_index) | ||
| if PREV_VERSION and prev_version_pattern in changelog_text | ||
| else len(changelog_text) | ||
| ) | ||
|
|
||
| if new_content: | ||
| return ( | ||
| changelog_text[:notes_start_index] | ||
| + f"{new_content}\n" | ||
| + changelog_text[notes_end_index:] | ||
| ) | ||
| else: | ||
| changeset_lines = changelog_text[notes_start_index:notes_end_index].split("\n") | ||
| # Remove the first two lines from the regular changeset format, ex: \n### Patch Changes | ||
| parsed_lines = "\n".join(changeset_lines[2:]) | ||
| updated_changelog = ( | ||
| changelog_text[:notes_start_index] | ||
| + parsed_lines | ||
| + changelog_text[notes_end_index:] | ||
| ) | ||
| updated_changelog = updated_changelog.replace( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global replacement of |
||
| f"## {VERSION}", f"## [{VERSION}]" | ||
| ) | ||
| return updated_changelog | ||
|
|
||
|
|
||
| with open(CHANGELOG_PATH, "r") as f: | ||
| changelog_content = f.read() | ||
|
|
||
| new_changelog = overwrite_changelog_section(changelog_content, NEW_CONTENT) | ||
| print( | ||
| "----------------------------------------------------------------------------------" | ||
| ) | ||
| print(new_changelog) | ||
| print( | ||
| "----------------------------------------------------------------------------------" | ||
| ) | ||
| # Write back to CHANGELOG.md | ||
| with open(CHANGELOG_PATH, "w") as f: | ||
| f.write(new_changelog) | ||
|
|
||
| print(f"{CHANGELOG_PATH} updated successfully!") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No check if
'## {VERSION}\n'exists. If not found,find()returns-1, causing an incorrect slice. Add validation.