Repository navigation
Add reusable release workflow for add-ons #581
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
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,93 @@ | ||
| #!/usr/bin/env python3 | ||
| """Changelog helpers for the add-on release workflow. | ||
|
|
||
| Add-on READMEs do not share one changelog format, so new entries copy the | ||
| heading and bullet style of the newest existing entry. | ||
|
|
||
| Usage: | ||
| addon-changelog.py ensure <readme> <version> Insert a placeholder entry if <version> has none. | ||
| addon-changelog.py notes <readme> <version> Print the bullets of the <version> entry. | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| MARKER = re.compile(r"^==\s*Changelog\s*==[ \t]*\r?\n?", re.MULTILINE) | ||
| VERSION = re.compile(r"\d+(?:\.\d+)+[0-9A-Za-z.-]*") | ||
|
|
||
|
|
||
| def read(readme): | ||
| # Bytes keep the original line endings; several add-on READMEs use CRLF. | ||
| return readme.read_bytes().decode() | ||
|
|
||
|
|
||
| def changelog_lines(text): | ||
| match = MARKER.search(text) | ||
| if not match: | ||
| raise SystemExit("README is missing the == Changelog == section") | ||
| return match.end(), text[match.end():].splitlines(keepends=True) | ||
|
|
||
|
|
||
| def is_heading(line, version=None): | ||
| stripped = line.strip().strip("=").strip() | ||
| if stripped.lower().startswith("version "): | ||
| stripped = stripped[8:].strip() | ||
| found = VERSION.fullmatch(stripped) | ||
| return bool(found) and (version is None or stripped == version) | ||
|
|
||
|
|
||
| def ensure(readme, version): | ||
| text = read(readme) | ||
| start, lines = changelog_lines(text) | ||
|
|
||
| if any(is_heading(line, version) for line in lines): | ||
| print(f"Changelog entry for {version} already present.") | ||
| return | ||
|
|
||
| newline = "\r\n" if "\r\n" in text else "\n" | ||
| heading = f"= {version} =" | ||
| bullet = "* " | ||
| offset = start | ||
| position = None | ||
| for line in lines: | ||
| if position is None and is_heading(line): | ||
| heading = VERSION.sub(version, line.strip(), count=1) | ||
| position = offset | ||
| if line.startswith(("- ", "* ")): | ||
| bullet = line[:2] | ||
| break | ||
| offset += len(line) | ||
|
|
||
| entry = f"{heading}{newline}{bullet}Enhancement: Various improvements and fixes.{newline}{newline}" | ||
| if position is None: | ||
| # No entries yet: put the first one on the line after the marker. | ||
| position = start | ||
| readme.write_bytes((text[:position] + entry + text[position:]).encode()) | ||
| print(f"Inserted a fallback changelog entry for {version}.") | ||
|
|
||
|
|
||
| def notes(readme, version): | ||
| _, lines = changelog_lines(read(readme)) | ||
| out = [] | ||
| capturing = False | ||
| for line in lines: | ||
| if is_heading(line): | ||
| if capturing: | ||
| break | ||
| capturing = is_heading(line, version) | ||
| continue | ||
| if capturing: | ||
| out.append(line.rstrip()) | ||
| print("\n".join(out).strip()) | ||
|
sorinmarta marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 4 or sys.argv[1] not in ("ensure", "notes"): | ||
| raise SystemExit(__doc__) | ||
| command, readme, version = sys.argv[1], Path(sys.argv[2]), sys.argv[3] | ||
| (ensure if command == "ensure" else notes)(readme, version) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.