Skip to content

Commit ee080e4

Browse files
committed
build: add version-sync lint and ship notices in install and release
Add tests/check-version (wired into `make lint`) asserting VERSION matches the man-page versions and that CITATION.cff carries a released version and date, plus a `make bump-version NEW=x.y.z` target that updates VERSION, the man-page dates/versions, and CITATION.cff together. Install THIRD-PARTY-NOTICES.md alongside LICENSE and copy it into the release tarball, so the attribution travels with every distributed copy.
1 parent 47bac92 commit ee080e4

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

.github/workflows/_cross-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
cp -a "${{ steps.builddir.outputs.dir }}/." "${DIR}/"
180180
rm -rf "${DIR}/obj"
181181
find "${DIR}/components" -type f ! -perm -u+x -delete
182-
cp README.md LICENSE "${DIR}/"
182+
cp README.md LICENSE THIRD-PARTY-NOTICES.md "${DIR}/"
183183
# Companion symbol-offset tool (arch-independent) + the docs, so the
184184
# tarball matches `make install` and the README's doc links resolve.
185185
mkdir -p "${DIR}/extra"

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ lint :
616616
@$(TEST_DIR)/check-fdt-unflatten
617617
@$(TEST_DIR)/check-ksymoff
618618
@$(TEST_DIR)/check-manpages
619+
@$(TEST_DIR)/check-version
619620
@$(TEST_DIR)/check-posture-diff
620621
@$(TEST_DIR)/check-posture-summary
621622
@$(TEST_DIR)/check-shellcheck
@@ -768,7 +769,7 @@ install : build
768769
install -m 755 "$$f" "$(DESTDIR)$(PREFIX)/libexec/kasld/"; \
769770
done
770771
install -d "$(DESTDIR)$(PREFIX)/share/doc/kasld"
771-
cp -R docs README.md LICENSE "$(DESTDIR)$(PREFIX)/share/doc/kasld/"
772+
cp -R docs README.md LICENSE THIRD-PARTY-NOTICES.md "$(DESTDIR)$(PREFIX)/share/doc/kasld/"
772773
install -d "$(DESTDIR)$(PREFIX)/share/man/man1"
773774
install -m 644 man/kasld.1 man/ksymoff.1 "$(DESTDIR)$(PREFIX)/share/man/man1/"
774775

@@ -885,6 +886,30 @@ print-deps:
885886
@echo " Build-Depends: gcc, make, libc-dev"
886887
@echo " Build-Depends (optional): zlib1g-dev (pthread ships in libc6)"
887888

889+
# Stamp a new version across the files that carry it as metadata: the VERSION
890+
# file (injected into the build as -DVERSION), the man-page .TH lines (version +
891+
# date), and — for a real release only — CITATION.cff (version + date-released;
892+
# a -dev string is not a citable identifier). The usage.md example output is
893+
# illustrative and intentionally not stamped. tests/check-version enforces that
894+
# these stay in step. Uses GNU sed -i.
895+
# make bump-version NEW=0.3.1 # cut a release
896+
# make bump-version NEW=0.3.2-dev # open the next dev cycle
897+
.PHONY: bump-version
898+
bump-version :
899+
@[ -n "$(NEW)" ] || { echo 'usage: make bump-version NEW=x.y.z (append -dev for a dev cycle)' >&2; exit 2; }
900+
@new='$(NEW)'; d=$$(date +%F); old=$$(cat VERSION 2>/dev/null); \
901+
printf '%s\n' "$$new" > VERSION; \
902+
for m in man/kasld.1 man/ksymoff.1; do \
903+
sed -i -E "1s/\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"/\"$$d\"/; 1s/\"kasld [^\"]*\"/\"kasld $$new\"/" "$$m"; \
904+
done; \
905+
case "$$new" in \
906+
*-dev) echo " note: '$$new' is a dev version — CITATION.cff left at the last release" ;; \
907+
*) sed -i -E "s/^version: .*/version: \"$$new\"/; s/^date-released: .*/date-released: \"$$d\"/" CITATION.cff; \
908+
echo " CITATION.cff -> version $$new, date-released $$d" ;; \
909+
esac; \
910+
echo " VERSION: $${old:-?} -> $$new (man pages dated $$d)"; \
911+
echo " next: review the diff, commit, and 'git tag v$$new' for a release"
912+
888913
.PHONY: help
889914
help:
890915
@echo
@@ -901,6 +926,7 @@ help:
901926
@echo " uninstall Remove installed files"
902927
@echo " clean Remove build directory"
903928
@echo " print-deps List build dependencies (libs + per-component flags)"
929+
@echo " bump-version Stamp NEW=x.y.z across VERSION, man pages, CITATION.cff"
904930
@echo
905931
@echo " Test targets:"
906932
@echo " test Build and run the unit suite + lint"

tests/check-version

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
# This file is part of KASLD - https://github.com/bcoles/kasld
3+
#
4+
# check-version — the version-carrying files stay in step, so a release does
5+
# not ship a binary that says one version while the man pages say another.
6+
#
7+
# Asserts:
8+
# - man/kasld.1 and man/ksymoff.1 `.TH` version == the VERSION file
9+
# (roff `\-` escapes are normalized before comparing).
10+
# - CITATION.cff has a `version:` and a `date-released:`, and the cited
11+
# version is a real release (not an in-development `-dev` string, which is
12+
# not a citable identifier — cite a release or a commit instead).
13+
#
14+
# `make bump-version V=x.y.z` updates all of these together.
15+
#
16+
# Usage: tests/check-version (also run by `make test`)
17+
# ---
18+
# <bcoles@gmail.com>
19+
20+
set -u
21+
ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
22+
23+
if [ -t 2 ]; then
24+
RED=$(printf '\033[31m')
25+
GREEN=$(printf '\033[32m')
26+
RESET=$(printf '\033[0m')
27+
else
28+
RED=
29+
GREEN=
30+
RESET=
31+
fi
32+
33+
fails=0
34+
fail() {
35+
printf '%scheck-version: FAIL%s — %s\n' "$RED" "$RESET" "$1" >&2
36+
fails=$((fails + 1))
37+
}
38+
39+
ver=$(cat "$ROOT/VERSION" 2>/dev/null)
40+
[ -n "$ver" ] || fail "VERSION file is empty or missing"
41+
42+
# Man-page .TH version: `"kasld <version>"`, with roff `\-` normalized to `-`.
43+
for m in kasld ksymoff; do
44+
mf="$ROOT/man/$m.1"
45+
mver=$(sed -n '1s/.*"kasld \([^"]*\)".*/\1/p' "$mf" | sed 's/\\//g')
46+
[ "$mver" = "$ver" ] ||
47+
fail "man/$m.1 version '$mver' != VERSION '$ver' (run: make bump-version V=$ver)"
48+
done
49+
50+
# CITATION.cff cites a released version (never -dev), with a release date.
51+
cff="$ROOT/CITATION.cff"
52+
if [ -f "$cff" ]; then
53+
cver=$(sed -n 's/^version: *"\([^"]*\)".*/\1/p' "$cff" | head -1)
54+
grep -q '^date-released:' "$cff" || fail "CITATION.cff: no date-released"
55+
case "$cver" in
56+
"") fail "CITATION.cff: no version" ;;
57+
*-dev) fail "CITATION.cff cites '$cver' — cite a release, not a -dev string" ;;
58+
esac
59+
fi
60+
61+
if [ "$fails" -ne 0 ]; then
62+
exit 1
63+
fi
64+
65+
printf '%scheck-version: OK%s (VERSION %s in step with man pages; CITATION.cff cites a release)\n' \
66+
"$GREEN" "$RESET" "$ver"

0 commit comments

Comments
 (0)