A commit build's claim tag has the canary claim shape with the commit kind; its version is X.Y.Z+commit.<stamp> (Termux X.Y.Z~commit.<stamp>-1; APT repo staging keeps refusing commit claims). release_version/tag_core/releaseVersion/ releaseTagVersion/deb_version accept it; tag_kind names the kind. Install stamps and icon generation of a commit build may carry its own claim tag and still say source commit-build, so every updater keeps refusing it; a commit tag without HERMES_BUILD_COMMIT is refused by the stamp writers and product identity rather than falling through to the stable identity and its latest feed. Salvaged from 98ee7de7c6, f8a42b0cc9, d9ead4e507, f161e6618d and 0f11098f12 in #145680, keeping stage_apt_repo closed to commit claims. Co-authored-by: BearHuddleston <bear@bearhuddleston.dev>
92 lines
3.1 KiB
Python
92 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Derive a Debian package version (or channel) from a hermes-agent release tag.
|
|
|
|
Pure function; imported by scripts/termux/build_deb.sh and unit-tested by
|
|
tests/scripts/test_termux_deb_version.py (Task 4 of .hermes/plans/2026-08-31_termux-deb.md).
|
|
|
|
Mapping:
|
|
v1.2.3 -> 1.2.3-1
|
|
canary.20260831T120000Z-v1.2.3 -> 1.2.3~canary.20260831T120000Z-1
|
|
|
|
The ``~`` ranks the canary below the corresponding stable in dpkg's version
|
|
ordering.
|
|
|
|
``--channel`` derives the release channel from the SAME tag regex: a tag with
|
|
a nightly timestamp is ``nightly``, everything else is ``stable``. This is the
|
|
single source of truth for the channel; workflows and other tooling must call
|
|
this instead of re-typing a case statement.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
|
|
_TAG_RE = re.compile(
|
|
r"^(?:(?P<kind>canary|commit)\.(?P<ts>20\d{6}T\d{6}Z)-)?"
|
|
r"v(?P<major>0|[1-9]\d{0,2})\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$"
|
|
)
|
|
|
|
|
|
def _match_tag(tag: str) -> re.Match[str]:
|
|
m = _TAG_RE.match(tag)
|
|
if m is None:
|
|
raise ValueError(
|
|
f"malformed release tag {tag!r}: expected v<MAJOR>.<MINOR>.<PATCH> "
|
|
"or canary|commit.<UTC timestamp>-v<MAJOR>.<MINOR>.<PATCH>"
|
|
)
|
|
return m
|
|
|
|
|
|
def deb_version_for_tag(tag: str) -> str:
|
|
"""Map a release tag to its Debian version. Raises ValueError on malformed tags."""
|
|
m = _match_tag(tag)
|
|
base = f"{m.group('major')}.{m.group('minor')}.{m.group('patch')}"
|
|
ts = m.group("ts")
|
|
if ts is None:
|
|
return f"{base}-1"
|
|
return f"{base}~{m.group('kind')}.{ts}-1"
|
|
|
|
|
|
def release_version_for_tag(tag: str) -> str:
|
|
"""The version a release tag carries: ``X.Y.Z``, ``X.Y.Z+canary.<stamp>`` or ``X.Y.Z+commit.<stamp>``.
|
|
|
|
The same value as hermes_cli.update_channel.release_version; build_deb.sh stamps it as the
|
|
package's base version and cannot import the application package.
|
|
"""
|
|
m = _match_tag(tag)
|
|
base = f"{m.group('major')}.{m.group('minor')}.{m.group('patch')}"
|
|
return f"{base}+{m.group('kind')}.{m.group('ts')}" if m.group("ts") else base
|
|
|
|
|
|
def channel_for_tag(tag: str) -> str:
|
|
"""Map a release tag to its channel: 'stable', 'canary' or 'commit'.
|
|
|
|
Derived from the same _TAG_RE as deb_version_for_tag, so the two can never
|
|
drift: a tag that yields a '~canary' deb version is canary, and the
|
|
malformed-tag rejection is identical. Commit builds never publish an APT repo.
|
|
"""
|
|
m = _match_tag(tag)
|
|
return m.group("kind") or "stable"
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
args = argv[1:]
|
|
mode = deb_version_for_tag
|
|
if args and args[0] in ("--channel", "--release-version"):
|
|
mode = channel_for_tag if args[0] == "--channel" else release_version_for_tag
|
|
args = args[1:]
|
|
if len(args) != 1:
|
|
print("usage: deb_version.py [--channel | --release-version] <tag>", file=sys.stderr)
|
|
return 2
|
|
try:
|
|
print(mode(args[0]))
|
|
except ValueError as exc:
|
|
print(f"deb_version: {exc}", file=sys.stderr)
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main(sys.argv))
|