Files
uconsole_asw_game/tools/prune_releases.py
T
Claude 9545789f80 Remove older version tags with their releases (1.3.75)
After deleting the older releases, the Windows workflow now also deletes
every git tag vX.Y.Z older than the current version, so only the newest
release and its tag stay on GitHub. The uConsole updater fetches only the
tag of releases/latest. Tags of another form (backup tags) are kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Nnvw4QEQCCWoLWoB9ba6h
2026-09-29 11:25:15 +00:00

47 lines
1.6 KiB
Python

"""List the release tags older than the current version (one tag per line).
The Windows workflow keeps only the newest release and its tag: after
publishing ``v<APP_VERSION>`` it pipes every release tag, and then every git
tag, into ``python tools/prune_releases.py <APP_VERSION>`` and deletes the
releases and tags printed here (Dominik, 2026-09-29). The uConsole updater
fetches only the tag of ``releases/latest``. Only tags of the form ``vX.Y.Z``
older than the current version are printed; anything newer (a later run that
finished first) or of another form (such as backup tags) is never touched.
"""
from __future__ import annotations
import re
import sys
_TAG = re.compile(r"v(\d+)\.(\d+)\.(\d+)")
def _version(text: str) -> tuple[int, int, int] | None:
match = _TAG.fullmatch(text.strip())
return tuple(int(part) for part in match.groups()) if match else None
def older_tags(current: str, tags) -> list[str]:
keep = _version(f"v{current}")
if keep is None:
raise ValueError(f"invalid version {current!r}")
return [tag.strip() for tag in tags
if (version := _version(tag)) is not None and version < keep]
def main(argv=None) -> int:
argv = sys.argv[1:] if argv is None else argv
if len(argv) != 1:
print("usage: prune_releases.py VERSION < tags", file=sys.stderr)
return 2
# Plain "\n" even on Windows: a "\r" would become part of the tag.
sys.stdout.reconfigure(newline="\n")
for tag in older_tags(argv[0], sys.stdin):
print(tag)
return 0
if __name__ == "__main__":
raise SystemExit(main())