From 8280e43d9524e134d2a6c1d12e52c790fb8df331 Mon Sep 17 00:00:00 2001 From: Joshua Lock Date: Mon, 15 Feb 2021 21:10:48 +0000 Subject: [PATCH] Add simple scripting to build specification releases Add some make driven automation to build releases of the specification and maintain an HTML index of releases. To be driven by a GitHub actions workflow calling make release with, i.e. mkdir build && cd build && make -f ../Makefile release Adds some helper scripts: * get_version.py: is a simple Python script which uses a regex to fetch the version number from a tuf-spec.md -- the script helps avoid dealing with different options between GNU grep (Linux) and BSD grep (macOS and other BSDs) * build_index.py: includes a string which replicates enough of the style of the bikeshed formatted specification to build an appropriately themed HTML page linking to latest, draft, and versioned releases Signed-off-by: Joshua Lock --- Makefile | 20 ++++- build_index.py | 203 +++++++++++++++++++++++++++++++++++++++++++++++++ get_version.py | 44 +++++++++++ 3 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 build_index.py create mode 100644 get_version.py diff --git a/Makefile b/Makefile index 9d56cc7..4c0ca38 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,19 @@ SHELL=/bin/bash -o pipefail -.PHONY: local +SPEC_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +.PHONY: spec -local: tuf-spec.md - bikeshed spec tuf-spec.md tuf-spec.html +spec: $(SPEC_DIR)/tuf-spec.md + bikeshed spec $(SPEC_DIR)/tuf-spec.md tuf-spec.html + +latest: spec + mkdir -p latest + cp tuf-spec.html latest/index.html + +versioned: spec + mkdir -p $(shell python3 $(SPEC_DIR)/get_version.py $(SPEC_DIR)/tuf-spec.md) + cp tuf-spec.html $(shell python3 $(SPEC_DIR)/get_version.py $(SPEC_DIR)/tuf-spec.md)/index.html + +index: + python3 $(SPEC_DIR)/build_index.py + +release: spec latest versioned diff --git a/build_index.py b/build_index.py new file mode 100644 index 0000000..c937de9 --- /dev/null +++ b/build_index.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python3 + +""" + + build_index.py + + + Joshua Lock + + + Feb 1, 2021 + + + See LICENSE-MIT for licensing information. + + + Quick and dirty script to generate an index of published specification + versions. + + Style cribbed from the bikeshed W3C theme we are using in our bikeshed + generated specification documents. +""" + +import os +import sys + +from subprocess import run + +html_header = """ + + + + The Update Framework Specification + + + + +
+

The Update Framework Specification

+
+
+
    +""" + +html_footer = """
+ + +""" + +def sanity_check(): + branch = None + + try: + branch = run("git branch --show-current".split(), capture_output=True).stdout + except Exception: + pass + + if branch != b"gh-pages\n": + print(f"build_index.py must be run from the 'gh-pages' branch (on '{branch}'") + sys.exit() + +def build_index(): + # sanity_check() + + html = html_header + + html_locations = ['latest', 'draft'] + dir_contents = sorted(os.listdir('.'), reverse=True) + for path in dir_contents: + if path.startswith('v'): + if not os.path.exists(f'{path}/index.html'): + continue + html_locations.append(path) + + for loc in html_locations: + link = f"
  • {loc}
  • \n" + html = html + link + + html = html + html_footer + + return html + +if __name__ == "__main__": + html = build_index() + with open('index.html', 'w') as index: + index.write(html) diff --git a/get_version.py b/get_version.py new file mode 100644 index 0000000..c2474f0 --- /dev/null +++ b/get_version.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +""" + + get_version.py + + + Joshua Lock + + + Feb 2, 2021 + + + See LICENSE-MIT for licensing information. + + + Quick and dirty script to get the version number from tuf-spec.md + + Unfortunately GNU grep and BSD grep take different options... +""" + +import re +import sys + +pattern = re.compile("VERSION (\d+\.\d+\.\d+)") + +def get_version(): + out = '' + spec = 'tuf-spec.md' + + if (len(sys.argv) > 1): + spec = sys.argv[1] + + with open(spec, 'r') as spec: + for line in spec: + for match in re.finditer(pattern, line): + if match.group(): + break + out = match.groups()[0] + + return f'v{out}' + +if __name__ == "__main__": + print(get_version())