Skip to content

Commit

Permalink
Add CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Aug 25, 2024
1 parent 249030e commit 236637d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ci/scripts/release-notes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from __future__ import annotations

import sys
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import TypeAlias

Version: TypeAlias = tuple[int, int] | tuple[int, int, int]


HERE = Path(__file__).parent

MARKER_F = "<!-- towncrier release notes start: feature -->"
MARKER_P = "<!-- towncrier release notes start: patch -->"

Expand Down Expand Up @@ -87,3 +93,27 @@ def insert_feature(rel_notes: str, version: Version) -> str:
# insert include for new .0 patch version
rel_notes = insert_patch(rel_notes, (*version, 0))
return rel_notes


def main(args: Sequence[str] | None = None) -> str | None:
if args is None:
args = sys.argv[1:]

if len(args) != 1:
return "Usage: python release-notes.py <version>"

version = tuple(map(int, args[0].split(".")))

index_path = HERE.parent.parent / "docs" / "release-notes" / "index.md"
index = index_path.read_text()
if len(version) == 2:
index = insert_feature(index, version)
elif len(version) == 3:
index = insert_patch(index, version)
else:
return f"Invalid version: {version!r}"
index_path.write_text(index)


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 236637d

Please sign in to comment.