]> git.ipfire.org Git - thirdparty/pdns.git/blob - builder-support/gen-version
Merge branch 'dnsdist-macos' of https://github.com/Habbie/pdns
[thirdparty/pdns.git] / builder-support / gen-version
1 #!/bin/sh
2 if [ ! -z "${BUILDER_VERSION}" ]; then
3 printf ${BUILDER_VERSION}
4 exit 0
5 fi
6
7 VERSION="unknown"
8
9 DIRTY=""
10 git status | grep -q clean || DIRTY='.dirty'
11
12 # Special environment variable to signal that we are building a release, as this
13 # has condequenses for the version number.
14 if [ "${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
24 fi
25
26 #
27 # Generate the version number based on the branch
28 #
29 if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
30 GIT_VERSION=""
31 if $(git rev-parse --abbrev-ref HEAD | grep -q 'rel/'); then
32 REL_TYPE="$(git rev-parse --abbrev-ref HEAD | cut -d/ -f 2 | cut -d- -f 1)"
33 GIT_VERSION="$(git describe --match=${REL_TYPE}-* --tags | cut -d- -f2-)"
34 fi
35
36 LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1)"
37 COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f2)"
38 GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f3)"
39
40 if [ -z "${GIT_VERSION}" ]; then
41 # We used 0.0.XXXXgHASH for master in the previous incarnation of our build pipeline.
42 # This now becomes 0.0.XXXX.0.gHASH, as 0.0.0.XXXX.gHASH (which is more correct)
43 # would break upgrades for those running master
44 # This _should_ be ok for forever is we stick to X.Y.Z for version numbers
45 LAST_TAG=0.0
46 COMMITS_SINCE_TAG="$(git rev-list --count 12c868770afc20b6cc0da439d881105151d557dd..HEAD 2> /dev/null).0"
47 [ "${COMMITS_SINCE_TAG}" = ".0" ] && COMMITS_SINCE_TAG=0.0
48 GIT_HASH="$(git rev-parse HEAD | cut -c1-10 2> /dev/null)"
49 fi
50
51 BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/[^[:alnum:]]//g;')"
52 [ "${BRANCH}" = ".master" ] && BRANCH=''
53
54 TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
55 if [ -n "${TAG}" ]; then # We're exactly on a tag
56 COMMITS_SINCE_TAG="0"
57 GIT_HASH="g$(git show --no-patch --format=format:%h HEAD 2>/dev/null)"
58 if [ -z "$GIT_HASH" ]; then
59 GIT_HASH="g$(git show --format=format:%h HEAD | head -n1)"
60 fi
61 fi
62
63 VERSION="${LAST_TAG}.${COMMITS_SINCE_TAG}${BRANCH}.g${GIT_HASH}${DIRTY}"
64 fi
65
66 printf $VERSION