-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0166957
commit 36b86c5
Showing
4 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -137,3 +137,6 @@ dmypy.json | |
|
||
# Ruff litner | ||
.ruff_cache/ | ||
|
||
# Archive | ||
.archive/ |
This file contains 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
This file contains 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,41 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from pte_stats import __version__ | ||
|
||
|
||
def main(): | ||
changelog = Path(r"docs/CHANGELOG.md") | ||
|
||
with changelog.open() as f: | ||
lines = f.readlines() | ||
|
||
insert_index: int = -1 | ||
for i in range(len(lines)): | ||
line = lines[i] | ||
if line.startswith("## Unreleased"): | ||
insert_index = i + 1 | ||
elif line.startswith(f"## [v{__version__}]"): | ||
print("CHANGELOG already up-to-date") | ||
return | ||
elif line.startswith("## [v"): | ||
break | ||
|
||
if insert_index < 0: | ||
raise RuntimeError("Couldn't find 'Unreleased' section") | ||
|
||
lines.insert(insert_index, "\n") | ||
lines.insert( | ||
insert_index + 1, | ||
f"## [v{__version__}]" | ||
"(https://github.com/richardkoehler/pte-stats/releases" | ||
f"/tag/v{__version__}) - " | ||
f"{datetime.now().strftime('%Y-%m-%d')}\n", | ||
) | ||
|
||
with changelog.open("w") as f: | ||
f.writelines(lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,83 @@ | ||
""" | ||
Prepares markdown release notes for GitHub releases. | ||
""" | ||
|
||
import os | ||
|
||
import packaging.version | ||
|
||
TAG = os.environ["TAG"] | ||
|
||
ADDED_HEADER = "### Added 🎉" | ||
CHANGED_HEADER = "### Changed ⚠️" | ||
FIXED_HEADER = "### Fixed ✅" | ||
REMOVED_HEADER = "### Removed 👋" | ||
|
||
|
||
def get_change_log_notes() -> str: | ||
in_current_section = False | ||
current_section_notes: list[str] = [] | ||
with open(r"docs/CHANGELOG.md") as changelog: | ||
for line in changelog: | ||
if line.startswith("## "): | ||
if line.startswith("## Unreleased"): | ||
continue | ||
if line.startswith(f"## [{TAG}]"): | ||
in_current_section = True | ||
continue | ||
break | ||
if in_current_section: | ||
if line.startswith("### Added"): | ||
line = ADDED_HEADER + "\n" | ||
elif line.startswith("### Changed"): | ||
line = CHANGED_HEADER + "\n" | ||
elif line.startswith("### Fixed"): | ||
line = FIXED_HEADER + "\n" | ||
elif line.startswith("### Removed"): | ||
line = REMOVED_HEADER + "\n" | ||
current_section_notes.append(line) | ||
assert current_section_notes | ||
return "## What's new\n\n" + "".join(current_section_notes).strip() + "\n" | ||
|
||
|
||
def get_commit_history() -> str: | ||
new_version = packaging.version.parse(TAG) | ||
|
||
# Pull all tags. | ||
os.popen("git fetch --tags") | ||
|
||
# Get all tags sorted by version, latest first. | ||
all_tags = ( | ||
os.popen("git tag -l --sort=-version:refname 'v*'").read().split("\n") | ||
) | ||
|
||
# Out of `all_tags`, find the latest previous version so that we can | ||
# collect all commits between that version and the new version we're about | ||
# to publish. Note that we ignore pre-releases unless the new version is | ||
# also a pre-release. | ||
last_tag: str | None = None | ||
for tag in all_tags: | ||
if not tag.strip(): # could be blank line | ||
continue | ||
version = packaging.version.parse(tag) | ||
if new_version.pre is None and version.pre is not None: | ||
continue | ||
if version < new_version: | ||
last_tag = tag | ||
break | ||
if last_tag is not None: | ||
commits = os.popen( | ||
f"git log {last_tag}..{TAG} --oneline --first-parent" | ||
).read() | ||
else: | ||
commits = os.popen("git log --oneline --first-parent").read() | ||
return "## Commits\n\n" + commits | ||
|
||
|
||
def main(): | ||
print(get_change_log_notes()) | ||
print(get_commit_history()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |