|
@@ -7,11 +7,18 @@ tagged, every note that was in the unreleased section *at the tagged commit*
|
|
|
moves into a new "== <version>" section. Notes added to the unreleased section
|
|
moves into a new "== <version>" section. Notes added to the unreleased section
|
|
|
after the release was cut stay where they are.
|
|
after the release was cut stay where they are.
|
|
|
|
|
|
|
|
|
|
+Each version section links back to the release on GitHub, which has the full
|
|
|
|
|
+release notes, and has an anchor that the GitHub release links to.
|
|
|
|
|
+
|
|
|
Usage:
|
|
Usage:
|
|
|
release_upgrade_notes.py <version> <released-file> <target-file>
|
|
release_upgrade_notes.py <version> <released-file> <target-file>
|
|
|
|
|
+ release_upgrade_notes.py --release-summary <version> <notes-file>
|
|
|
|
|
|
|
|
<released-file> is upgrade_notes.adoc as it was at the release tag, and
|
|
<released-file> is upgrade_notes.adoc as it was at the release tag, and
|
|
|
<target-file> is the copy to update in place (normally on the next branch).
|
|
<target-file> is the copy to update in place (normally on the next branch).
|
|
|
|
|
+
|
|
|
|
|
+--release-summary prints the "Upgrade warnings, or breaking changes" list for
|
|
|
|
|
+the GitHub release of <version>, from the unreleased notes in <notes-file>.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
@@ -20,6 +27,9 @@ import sys
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
UNRELEASED_HEADING = "== Next release (unreleased)"
|
|
UNRELEASED_HEADING = "== Next release (unreleased)"
|
|
|
|
|
+GITHUB_RELEASE_URL = "https://github.com/OliveTin/OliveTin/releases/tag/{version}"
|
|
|
|
|
+UPGRADE_NOTES_URL = "https://docs.olivetin.app/upgrade/upgrade_notes.html"
|
|
|
|
|
+NO_UPGRADE_NOTES = "- No such issues between the last release and this version.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
def split_sections(lines: list[str], prefix: str) -> tuple[list[str], list[list[str]]]:
|
|
def split_sections(lines: list[str], prefix: str) -> tuple[list[str], list[list[str]]]:
|
|
@@ -79,8 +89,19 @@ def released_keys(released_lines: list[str]) -> set[str]:
|
|
|
return {note_key(note) for note in found[1]}
|
|
return {note_key(note) for note in found[1]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def version_anchor(version: str) -> str:
|
|
|
|
|
+ return "release-" + version.replace(".", "-")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def build_version_section(version: str, notes: list[list[str]]) -> list[str]:
|
|
def build_version_section(version: str, notes: list[list[str]]) -> list[str]:
|
|
|
- section = [f"== {version}\n", "\n"]
|
|
|
|
|
|
|
+ release_url = GITHUB_RELEASE_URL.format(version=version)
|
|
|
|
|
+ section = [
|
|
|
|
|
+ f"[#{version_anchor(version)}]\n",
|
|
|
|
|
+ f"== {version}\n",
|
|
|
|
|
+ "\n",
|
|
|
|
|
+ f"See the {release_url}[{version} release notes on GitHub] for everything in this release.\n",
|
|
|
|
|
+ "\n",
|
|
|
|
|
+ ]
|
|
|
for note in notes:
|
|
for note in notes:
|
|
|
section.extend(note)
|
|
section.extend(note)
|
|
|
return section
|
|
return section
|
|
@@ -126,7 +147,59 @@ def move_released_notes(version: str, released_lines: list[str], target_lines: l
|
|
|
return result if moved else None
|
|
return result if moved else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def note_title(note: list[str]) -> str:
|
|
|
|
|
+ for line in note:
|
|
|
|
|
+ if line.startswith("=== "):
|
|
|
|
|
+ return line[4:].strip()
|
|
|
|
|
+ return ""
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def note_anchor(note: list[str]) -> str:
|
|
|
|
|
+ for line in note:
|
|
|
|
|
+ if line.startswith("[#"):
|
|
|
|
|
+ return line.strip()[2:-1]
|
|
|
|
|
+ return ""
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def markdown_link(text: str, url: str) -> str:
|
|
|
|
|
+ escaped = text.replace("[", "\\[").replace("]", "\\]")
|
|
|
|
|
+ return f"[{escaped}]({url})"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def release_summary(version: str, lines: list[str]) -> str:
|
|
|
|
|
+ """Markdown for the GitHub release, linking to the notes that ship in it.
|
|
|
|
|
+
|
|
|
|
|
+ Links point at the version section that the release workflow creates after
|
|
|
|
|
+ the tag is pushed, and at each note's own anchor, which exists already.
|
|
|
|
|
+ """
|
|
|
|
|
+ found = unreleased_notes(lines)
|
|
|
|
|
+ notes = found[1] if found else []
|
|
|
|
|
+ if not notes:
|
|
|
|
|
+ return NO_UPGRADE_NOTES
|
|
|
|
|
+
|
|
|
|
|
+ version_url = f"{UPGRADE_NOTES_URL}#{version_anchor(version)}"
|
|
|
|
|
+ summary = [f"- This release has {markdown_link('upgrade notes', version_url)}. Read them before you upgrade:\n"]
|
|
|
|
|
+ for note in notes:
|
|
|
|
|
+ anchor = note_anchor(note)
|
|
|
|
|
+ url = f"{UPGRADE_NOTES_URL}#{anchor}" if anchor else version_url
|
|
|
|
|
+ summary.append(f" - {markdown_link(note_title(note), url)}\n")
|
|
|
|
|
+ return "".join(summary)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def print_release_summary(argv: list[str]) -> int:
|
|
|
|
|
+ if len(argv) != 4:
|
|
|
|
|
+ print(__doc__, file=sys.stderr)
|
|
|
|
|
+ return 2
|
|
|
|
|
+
|
|
|
|
|
+ version, notes_path = argv[2], Path(argv[3])
|
|
|
|
|
+ print(release_summary(version, notes_path.read_text().splitlines(keepends=True)), end="")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def main(argv: list[str]) -> int:
|
|
def main(argv: list[str]) -> int:
|
|
|
|
|
+ if len(argv) > 1 and argv[1] == "--release-summary":
|
|
|
|
|
+ return print_release_summary(argv)
|
|
|
|
|
+
|
|
|
if len(argv) != 4:
|
|
if len(argv) != 4:
|
|
|
print(__doc__, file=sys.stderr)
|
|
print(__doc__, file=sys.stderr)
|
|
|
return 2
|
|
return 2
|