From 073514fc21c8735dccffd007238e7afaea1abc7c Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 14 Jun 2020 18:24:20 +0200 Subject: [PATCH] docs/publish.sh: only render latest (patch+rc) version for each (major,minor) versio. --- docs/gen-sphinx-versioning-flags.py | 76 +++++++++++++++++++++++++++++ docs/publish.sh | 5 +- 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 docs/gen-sphinx-versioning-flags.py diff --git a/docs/gen-sphinx-versioning-flags.py b/docs/gen-sphinx-versioning-flags.py new file mode 100644 index 0000000..a3ac8f4 --- /dev/null +++ b/docs/gen-sphinx-versioning-flags.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import subprocess +import re + +output = subprocess.run(["git", "tag", "-l"], capture_output=True, check=True, text=True) +tagRE = re.compile(r"^v(?P\d+)\.(?P\d+)\.(?P\d+)(-rc(?P\d+))?$") +class Tag: + orig: str + major: int + minor: int + patch: int + rc: int + + def __str__(self): + return self.orig + + def __repr__(self): + return self.orig + +tags = [] +for line in output.stdout.split("\n"): + m = tagRE.match(line) + if not m: + continue + m = m.groupdict() + + t = Tag() + t.orig = line + t.major = int(m["major"]) + t.minor = int(m["minor"]) + t.patch = int(m["patch"]) + t.rc = int(m["rc"] if m["rc"] is not None else 0) + + tags.append(t) + +by_major_minor = {} + +for tag in tags: + key = (tag.major, tag.minor) + l = by_major_minor.get(key, []) + l.append(tag) + by_major_minor[key] = l + +latest_by_major_minor = [] +for (mm, l) in by_major_minor.items(): + # sort ascending by patch-level (rc's weigh less) + l.sort(key=lambda tag: (tag.patch, int(tag.rc == 0), tag.rc)) + latest_by_major_minor.append(l[-1]) +latest_by_major_minor.sort(key=lambda tag: (tag.major, tag.minor)) + +# print(by_major_minor) +# print(latest_by_major_minor) + +cmdline = [] + +for latest_patch in latest_by_major_minor: + cmdline.append("--whitelist-tags") + cmdline.append(f"^{re.escape(latest_patch.orig)}$") + +# we want to render the latest non-rc version as the default page +# (latest_by_major_minor is already sorted) +default_version = latest_by_major_minor[-1] +for tag in reversed(latest_by_major_minor): + if tag.rc == 0: + default_version = tag + break + +cmdline.extend(["--root-ref", f"{default_version}"]) +cmdline.extend(["--banner-main-ref", f"{default_version}"]) +cmdline.extend(["--show-banner"]) +cmdline.extend(["--sort", "semver"]) + +cmdline.extend(["--whitelist-branches", "master"]) + +print(" ".join(cmdline)) \ No newline at end of file diff --git a/docs/publish.sh b/docs/publish.sh index 57be197..1915864 100755 --- a/docs/publish.sh +++ b/docs/publish.sh @@ -51,11 +51,10 @@ git rm -rf . popd echo "building site" + set -e sphinx-versioning build \ - --show-banner \ - --whitelist-branches '^master$' \ - --whitelist-tags '(v)?\d+\.[1-9][0-9]*.\d+$' \ + $(python3 gen-sphinx-versioning-flags.py) \ docs ./public_git \ -- -c sphinxconf # older conf.py throw errors because they used # version = subprocess.show_output(["git", "describe"])