From cf0d7b4cd0c74e99655c1bc57e2ca5f6ea99ba03 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 30 Jun 2022 19:46:40 +0200 Subject: [PATCH] Determine version dynamically from git 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. --- .github/workflows/tests.yml | 3 +++ .gitignore | 1 + meson.build | 4 +++- src/getversion.sh | 15 +++++++++++++++ tests/run-alpine | 2 +- tests/run-gentoo | 4 ++++ tests/run-nix | 3 ++- 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 src/getversion.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a8197429..a9328741 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: | diff --git a/.gitignore b/.gitignore index b052459e..a0848c48 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .deps .dirstamp .libs +.version *.la *.lo *.o diff --git a/meson.build b/meson.build index 2ed90270..e977e84e 100644 --- a/meson.build +++ b/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' @@ -44,6 +44,8 @@ if cc.has_function('__fxstatat', prefix: '#include ') add_project_arguments('-DHAVE_FXSTATAT', language: 'c') endif +meson.add_dist_script(srcdir / 'getversion.sh') + # # dependencies # diff --git a/src/getversion.sh b/src/getversion.sh new file mode 100755 index 00000000..0305852b --- /dev/null +++ b/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 diff --git a/tests/run-alpine b/tests/run-alpine index 699e2bfd..f3ae9317 100755 --- a/tests/run-alpine +++ b/tests/run-alpine @@ -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 diff --git a/tests/run-gentoo b/tests/run-gentoo index 5051057c..1b24f9ba 100755 --- a/tests/run-gentoo +++ b/tests/run-gentoo @@ -19,6 +19,10 @@ $RUNC run --interactive ${OPTS:-} \ docker.io/gentoo/stage3 /bin/sh -eux <