]> git.ipfire.org Git - thirdparty/pdns.git/blame - builder-support/gen-version
take lmdb change from bf2b8dc94331b50bd839dc8f5b188664637c7b31
[thirdparty/pdns.git] / builder-support / gen-version
CommitLineData
d45c935b 1#!/bin/sh
195843ef
PL
2if [ ! -z "${BUILDER_VERSION}" ]; then
3 printf ${BUILDER_VERSION}
d45c935b
PL
4 exit 0
5fi
6
7VERSION="unknown"
8
9DIRTY=""
10git status | grep -q clean || DIRTY='.dirty'
11
12# Special environment variable to signal that we are building a release, as this
39990e57 13# has consequenses for the version number.
d45c935b
PL
14if [ "${IS_RELEASE}" = "YES" ]; then
15 TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
16 if [ -n "${TAG}" ]; then
17 # We're on a tag
18 echo "${TAG}${DIRTY}" > .version
19 printf "${TAG}${DIRTY}"
20 exit 0
21 fi
22 echo 'This is not a tag, either tag this commit or do not set $IS_RELEASE' >&2
23 exit 1
24fi
25
26#
27# Generate the version number based on the branch
28#
29if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
39990e57
PL
30 if [ -n "${BUILDER_MODULES}" ]; then
31 match=${BUILDER_MODULES}
32 [ $match = "authoritative" ] && match='auth'
33 [ $match = "recursor" ] && match='rec'
34 GIT_VERSION="$(git describe --match=${match}-* --tags | cut -d- -f2-)"
35 if [ $(echo ${GIT_VERSION} | awk -F"-" '{print NF-1}') = '3' ]; then
36 # A prerelease happened before
37 LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1-2)"
38 COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f3)"
39 GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f4)"
40 else
41 LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1)"
42 COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f2)"
43 GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f3)"
44 fi
d45c935b 45 fi
195843ef 46
195843ef 47 if [ -z "${GIT_VERSION}" ]; then
39990e57
PL
48 # BUILDER_SUPPORT has more than one product listed, fall back to the 0.0.0 logic
49
7af16b66
PL
50 # We used 0.0.XXXXgHASH for master in the previous incarnation of our build pipeline.
51 # This now becomes 0.0.XXXX.0.gHASH, as 0.0.0.XXXX.gHASH (which is more correct)
52 # would break upgrades for those running master
0fd84c6f 53 # This _should_ be ok for forever is we stick to X.Y.Z for version numbers
7af16b66
PL
54 LAST_TAG=0.0
55 COMMITS_SINCE_TAG="$(git rev-list --count 12c868770afc20b6cc0da439d881105151d557dd..HEAD 2> /dev/null).0"
d29bcb8e 56 [ "${COMMITS_SINCE_TAG}" = ".0" ] && COMMITS_SINCE_TAG=0.0
39990e57 57 GIT_HASH="g$(git rev-parse HEAD | cut -c1-10 2> /dev/null)"
195843ef
PL
58 fi
59
60 BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/[^[:alnum:]]//g;')"
195843ef
PL
61
62 TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
63 if [ -n "${TAG}" ]; then # We're exactly on a tag
64 COMMITS_SINCE_TAG="0"
65 GIT_HASH="g$(git show --no-patch --format=format:%h HEAD 2>/dev/null)"
66 if [ -z "$GIT_HASH" ]; then
67 GIT_HASH="g$(git show --format=format:%h HEAD | head -n1)"
68 fi
69 fi
70
39990e57 71 VERSION="${LAST_TAG}.${COMMITS_SINCE_TAG}${BRANCH}.${GIT_HASH}${DIRTY}"
d45c935b
PL
72fi
73
74printf $VERSION