Skip to content

Commit

Permalink
Determine version dynamically from git
Browse files Browse the repository at this point in the history
Ship a ./version file so that this also works when building from dist
tarballs. Add a little helper shell script to determine this.

This enables us to reduce the release process to merely pushing a signed
tag.
  • Loading branch information
martinpitt committed Jul 1, 2022
1 parent 23a842d commit cf0d7b4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Expand Up @@ -31,6 +31,9 @@ jobs:
steps:
- name: Clone repository
uses: actions/checkout@v2
with:
# need this to also fetch tags
fetch-depth: 0

- name: Run unit tests
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
.deps
.dirstamp
.libs
.version
*.la
*.lo
*.o
Expand Down
4 changes: 3 additions & 1 deletion meson.build
@@ -1,5 +1,5 @@
project('umockdev', 'c', 'vala',
version: run_command('sed', '-rn', '1 { s/^.*\[([0-9.]+)\].*/\\1/; p }', 'NEWS', check: true).stdout().strip(),
version: run_command(meson.current_source_dir() / 'src' / 'getversion.sh', check: true).stdout().strip(),
license: 'LGPLv2.1+')

srcdir = meson.current_source_dir() / 'src'
Expand Down Expand Up @@ -44,6 +44,8 @@ if cc.has_function('__fxstatat', prefix: '#include <sys/stat.h>')
add_project_arguments('-DHAVE_FXSTATAT', language: 'c')
endif

meson.add_dist_script(srcdir / 'getversion.sh')

#
# dependencies
#
Expand Down
15 changes: 15 additions & 0 deletions src/getversion.sh
@@ -0,0 +1,15 @@
#!/bin/sh
ROOT=$(dirname $(dirname $(realpath "$0")))
if [ -n "${MESON_SOURCE_ROOT:-}/.git" ] && VER=$(git -C "$MESON_SOURCE_ROOT" describe); then
# make version number distribution friendly
VER=$(echo "$VER" | sed 's/-/./g')
# when invoked as dist script, write the stamp; this is false when invoked from project.version()
[ -z "${MESON_DIST_ROOT:-}" ] || echo "$VER" > "${MESON_DIST_ROOT}/.version"
echo "$VER"
# when invoked from a tarball, it should be in the source root
elif [ -e "${ROOT}/.version" ]; then
cat "${ROOT}/.version"
else
echo "ERROR: Neither a git checkout nor .version, cannot determine version" >&2
exit 1
fi
2 changes: 1 addition & 1 deletion tests/run-alpine
Expand Up @@ -15,7 +15,7 @@ $RUNC run --interactive ${OPTS:-} --volume `pwd`:/source:ro ${1:-docker.io/alpin
trap '[ \$? -eq 0 ] || exit 1' EXIT
# install build dependencies
apk add --no-cache meson gcc musl-dev glib-dev eudev-dev libpcap-dev make vala linux-headers xz usbutils ${EXTRA_PACKAGES:-}
apk add --no-cache meson git gcc musl-dev glib-dev eudev-dev libpcap-dev make vala linux-headers xz usbutils ${EXTRA_PACKAGES:-}
# run build as user
adduser -D build
Expand Down
4 changes: 4 additions & 0 deletions tests/run-gentoo
Expand Up @@ -19,6 +19,10 @@ $RUNC run --interactive ${OPTS:-} \
docker.io/gentoo/stage3 /bin/sh -eux <<EOF
# install build dependencies
ACCEPT_KEYWORDS="~*" emerge dev-util/umockdev --with-test-deps --onlydeps
# install git, "meson dist" dependency
emerge dev-vcs/git
git config --global safe.directory /source
cd /source
export VALAC=\$(ls /usr/bin/valac-* |sort | tail -n1)
Expand Down
3 changes: 2 additions & 1 deletion tests/run-nix
Expand Up @@ -26,8 +26,9 @@ in pkgs.umockdev.overrideAttrs (attrs: {
preCheck = "";
doCheck = true;
nativeBuildInputs = attrs.nativeBuildInputs ++ [ ${DEBUG:+pkgs.breakpointHook} ];
# git is a "meson dist" time dependency
# libpcap is a new dependency, it can be removed again later
buildInputs = attrs.buildInputs ++ [ pkgs.libpcap ];
buildInputs = attrs.buildInputs ++ [ pkgs.git pkgs.libpcap ];
})
EOG
Expand Down

0 comments on commit cf0d7b4

Please sign in to comment.