vpnhide/scripts/changelog.py
okhsunrog ad2590a453 refactor(scripts): unreleased section + rename scripts
Rework the changelog and release flow to remove the aspirational
top-level version that made it unclear whether new entries were
landing in an already-released section.

Schema change: `changelog.json` now has an explicit `unreleased`
object instead of hoisting the upcoming version to the top level. The
old `{version, sections, history}` layout becomes
`{unreleased, history}`, with the previously-released version moved
into `history[0]`.

New entries always go into `unreleased` via `changelog.py`. Releasing
is a single atomic operation (`release.py X.Y.Z`) that promotes
`unreleased` into `history[0]` with the target version number,
propagates the version to every source file, and regenerates the
markdown artifacts.

Script renames:
- `_changelog.py` → `changelog_lib.py` (no more underscore-prefixed
  module that's imported by two siblings)
- `changelog-add.py` → `changelog.py`
- `update-version.py` → `release.py` (does more than just version
  propagation — the name now reflects the full release action)

CHANGELOG.md rendering follows Keep a Changelog: a `## [Unreleased]`
block appears on top only when there are unreleased entries; the
update-json/changelog.md shown in Magisk/KSU popups still skips
Unreleased (only released versions make sense there).

Docs (docs/changelog.md, docs/releasing.md, CONTRIBUTING.md, CLAUDE.md)
updated with the new commands and the clarified model.

CLAUDE.md additionally gains a "read these before doing any work"
section that lists the contributor docs — so future sessions load the
workflow rules into context instead of skipping them as optional.
2026-04-17 14:34:47 +03:00

63 lines
1.6 KiB
Python
Executable file

#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "rich",
# ]
# ///
"""Append a bilingual entry to the upcoming `unreleased` section.
Usage:
changelog.py <type> "<EN text>" "<RU text>"
Types: added, changed, fixed, removed, deprecated, security
Writes the JSON source and regenerates CHANGELOG.md + update-json/changelog.md.
For the release flow (rotate unreleased into history, bump all version
files), use `release.py` instead.
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from changelog_lib import ( # type: ignore[import-not-found]
VALID_TYPES,
append_unreleased,
load_json,
save_json,
write_md,
)
from rich.console import Console
def main() -> int:
console = Console()
if len(sys.argv) != 4:
console.print(
"[red]usage:[/red] changelog.py <type> '<EN text>' '<RU text>'",
)
console.print(f" types: {', '.join(VALID_TYPES)}")
return 2
type_, en, ru = sys.argv[1], sys.argv[2], sys.argv[3]
if type_ not in VALID_TYPES:
console.print(f"[red]error:[/red] invalid type {type_!r}")
console.print(f" valid: {', '.join(VALID_TYPES)}")
return 2
data = load_json()
append_unreleased(data, type_, en, ru)
save_json(data)
write_md(data)
console.print(f"[green]added[/green] \\[{type_}] entry to unreleased")
console.print(f" [cyan]en:[/cyan] {en}")
console.print(f" [cyan]ru:[/cyan] {ru}")
return 0
if __name__ == "__main__":
sys.exit(main())