Skip to content

Commit

Permalink
Add releng/version.sh to manage release versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ahesford committed Nov 20, 2023
1 parent 6a393e2 commit 39b4411
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 8 deletions.
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ MANDIR=$(PREFIX)/share/man
BINDIR=$(PREFIX)/bin
EXAMPLES=$(PREFIX)/share/examples/zfsbootmenu

VERSION=$(shell grep 'our $$VERSION' bin/generate-zbm | \
head -n 1 | sed -e "s/.*=[[:space:]]*'//" -e "s/'.*//" )

.PHONY: install core dracut initcpio zbm-release show-version

install: core dracut initcpio zbm-release

core:
core: zbm-release
./install-tree.sh zfsbootmenu "$(DESTDIR)/$(MODDIR)/zfsbootmenu"
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
install -m 0755 -t "$(DESTDIR)/$(BINDIR)" -D bin/*
Expand All @@ -36,8 +33,7 @@ initcpio:
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf

zbm-release:
[ -n "$(VERSION)" ] && sed -e 's/@@VERSION@@/$(VERSION)/' \
zfsbootmenu/zbm-release > "$(DESTDIR)/$(MODDIR)/zfsbootmenu/zbm-release"
./releng/version.sh -u

show-version:
@echo $(VERSION)
@ ./releng/version.sh
8 changes: 7 additions & 1 deletion releng/tag-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ if ! (head -n 1 "${relnotes}" | grep -q "ZFSBootMenu ${tag}\b"); then
fi

# Update version in generate-zbm
sed -i bin/generate-zbm -e "s/our \$VERSION.*/our \$VERSION = '${release}';/"
if [ -x releng/version.sh ]; then
error "ERROR: unable to update release version"
fi

if ! out="$( releng/version.sh -v "${release}" -u )"; then
error "ERROR: ${out}"
fi

# Push updates for the release
git add bin/generate-zbm docs/ zfsbootmenu/help-files/
Expand Down
133 changes: 133 additions & 0 deletions releng/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/sh
# vim: softtabstop=2 shiftwidth=2 expandtab

usage() {
cat <<-EOF
USAGE: $0 [options]
OPTIONS
-h
Display this message and exit
-u
Update zbm-release and generate-zbm version information
-v <version>
Specify a particular version to use
EOF
}

detect_version() {
# If git-describe does the job, the job is done
version="$(git describe --tags HEAD 2>/dev/null)" || version=""

case "${version}" in
v[0-9]*) version="${version#v}"
esac

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi

# Otherwise, use git-rev-parse if possible
if branch="$(git rev-parse --abbrev-rev HEAD 2>/dev/null)"; then
case "${branch}" in
v[0-9]*) branch="${branch#v}"
esac

hash="$(git rev-parse --short HEAD 2>/dev/null)" || hash=""
[ -n "${hash}" ] && version="${branch:-UNKNOWN} (${hash})"

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi

# Everything fell apart, so just try reading zbm-release
relfile="zfsbootmenu/zbm-release"
if [ -r "${relfile}" ]; then
# shellcheck disable=SC2153
# shellcheck disable=SC1090
version="$( . "${relfile}" 2>/dev/null && echo "${VERSION}" )" || version=""

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi

# If there is no zbm-release, look to generate-zbm
genzbm="bin/generate-zbm"
if [ -r "${genzbm}" ]; then
# shellcheck disable=SC2016
if verline="$(grep 'our $VERSION[[:space:]]*=' "${genzbm}")"; then
version="$(echo "${verline}" | head -n1 | sed -e "s/.*=[[:space:]]*['\"]//" -e "s/['\"].*//")" || version=""
if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi
fi

# There is apparently no version
echo "UNKNOWN"
return 1
}

update_version() {
version="${1?a version is required}"

# Write zbm-release
if [ -d zfsbootmenu ] && [ -w zfsbootmenu ]; then
echo "Updating zfsbootmenu/zbm-release"
cat > zfsbootmenu/zbm-release <<-EOF
NAME="ZFSBootMenu"
PRETTY_NAME="ZFSBootMenu"
ID="zfsbootmenu"
ID_LIKE="void"
HOME_URL="https://zfsbootmenu.org"
DOCUMENTATION_URL="https://docs.zfsbootmenu.org"
BUG_REPORT_URL="https://github.com/zbm-dev/zfsbootmenu/issues"
SUPPORT_URL="https://github.com/zbm-dev/zfsbootmenu/discussions"
VERSION="${version}"
EOF
fi

# Update generate-zbm
if [ -w bin/generate-zbm ]; then
echo "Updating bin/generate-zbm"
sed -e "s/our \$VERSION.*/our \$VERSION = '${version}';/" -i bin/generate-zbm
fi
}

version=
update=
while getopts "huv:" opt; do
case "${opt}" in
u)
update="yes"
;;
v)
version="${OPTARG}"
;;
h)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done

[ -n "${version}" ] || version="$(detect_version)"

if [ "${update}" = yes ]; then
update_version "${version}"
else
echo "ZFSBootMenu version: ${version}"
fi

0 comments on commit 39b4411

Please sign in to comment.