APEX_VERSION in src/apex.h is the only source of truth, and nothing compared it with what users read. SECURITY.md claimed 0.23.x while the tree was at 0.30.0 for seven releases. tests/version_check.py now checks five places and names each disagreement: man page .TH, README status line, top CHANGELOG heading, SECURITY supported line (<major>.<minor>.x) and the Makefile tarball name (which must derive from APEX_VERSION, not hardcode it). It runs first in tests/run.sh, has its own make version-check target, and is the first step of make release-check. Bump 1.0.0 -> 1.0.1 with all five updated. Red proof: leaving the man page at 1.0.0 fails with 'docs/apex-twin.1 .TH says 1.0.0, header says 1.0.1' and run.sh stops before the suite. Verified: make test (version check + gate audit + 334 checks), make analyze 0, make release-check green through distcheck 1.0.1.
123 lines
3.9 KiB
Python
Executable File
123 lines
3.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""One version, five places.
|
|
|
|
APEX_VERSION in src/apex.h is the only source of truth. Everything a user or a
|
|
package reads has to agree with it: the man page .TH, the README status line,
|
|
the top CHANGELOG heading, the SECURITY supported line and the tarball name the
|
|
Makefile derives. Seven releases drifted because nothing checked; this does.
|
|
|
|
Exit 1 with a named failure per place that disagrees.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
def read(rel):
|
|
with open(os.path.join(HERE, rel), encoding="utf-8") as f:
|
|
return f.read()
|
|
|
|
|
|
def read_version():
|
|
m = re.search(r'^#define APEX_VERSION "([0-9]+\.[0-9]+\.[0-9]+)"',
|
|
read("src/apex.h"), re.M)
|
|
return m.group(1) if m else None
|
|
|
|
|
|
def check_man(version):
|
|
m = re.search(r'^\.TH\s+\S+\s+\d+\s+"[^"]*"\s+"apex-twin\s+([^"]+)"',
|
|
read("docs/apex-twin.1"), re.M)
|
|
if m is None:
|
|
return "docs/apex-twin.1 has no .TH with an apex-twin version"
|
|
if m.group(1) != version:
|
|
return "docs/apex-twin.1 .TH says %s, header says %s" % (m.group(1),
|
|
version)
|
|
return None
|
|
|
|
|
|
def check_readme(version):
|
|
body = read("README.md")
|
|
m = re.search(r"^## Status\s*$", body, re.M)
|
|
if m is None:
|
|
return "README.md has no ## Status section"
|
|
rest = body[m.end():].lstrip("\n")
|
|
if not rest.startswith(version + "."):
|
|
first = rest.splitlines()[0] if rest else "(empty)"
|
|
return "README.md status starts %r, expected %r" % (first[:40],
|
|
version + ".")
|
|
return None
|
|
|
|
|
|
def check_changelog(version):
|
|
m = re.search(r"^## ([0-9]+\.[0-9]+\.[0-9]+)", read("CHANGELOG.md"), re.M)
|
|
if m is None:
|
|
return "CHANGELOG.md has no version heading"
|
|
if m.group(1) != version:
|
|
return "CHANGELOG.md top heading is %s, header says %s" % (m.group(1),
|
|
version)
|
|
return None
|
|
|
|
|
|
def check_security(version):
|
|
body = read("SECURITY.md")
|
|
m = re.search(r"^## Supported versions\s*$", body, re.M)
|
|
if m is None:
|
|
return "SECURITY.md has no 'Supported versions' section"
|
|
tail = body[m.end():]
|
|
nxt = re.search(r"^## ", tail, re.M)
|
|
section = tail[:nxt.start()] if nxt else tail
|
|
major, minor, _ = version.split(".")
|
|
want = "%s.%s.x" % (major, minor)
|
|
if want not in section:
|
|
return "SECURITY.md supported line does not name %s" % want
|
|
return None
|
|
|
|
|
|
def check_makefile(version):
|
|
body = read("Makefile")
|
|
if "src/apex.h" not in body or "APEX_VERSION" not in body:
|
|
return "Makefile does not read APEX_VERSION from src/apex.h"
|
|
if re.search(r"apex-twin-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz", body):
|
|
return "Makefile hardcodes a versioned tarball name"
|
|
m = re.search(r"^DISTNAME\s*:=\s*apex-twin-\$\(VERSION\)\s*$", body, re.M)
|
|
if m is None:
|
|
return "Makefile DISTNAME is not apex-twin-$(VERSION)"
|
|
return None
|
|
|
|
|
|
CHECKS = (
|
|
("man page", check_man),
|
|
("README status", check_readme),
|
|
("CHANGELOG", check_changelog),
|
|
("SECURITY", check_security),
|
|
("Makefile", check_makefile),
|
|
)
|
|
|
|
|
|
def main():
|
|
version = read_version()
|
|
if version is None:
|
|
print("FAIL src/apex.h: no APEX_VERSION")
|
|
return 1
|
|
failures = []
|
|
for name, fn in CHECKS:
|
|
why = fn(version)
|
|
if why is None:
|
|
print("ok %-14s %s" % (name, version))
|
|
else:
|
|
print("FAIL %-14s %s" % (name, why))
|
|
failures.append(name)
|
|
if failures:
|
|
print("version-check: %d of %d places disagree with APEX_VERSION %s" %
|
|
(len(failures), len(CHECKS), version))
|
|
return 1
|
|
print("version-check: APEX_VERSION %s is consistent in %d places" %
|
|
(version, len(CHECKS)))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|