]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
gen-version: set the version number based on commits since root
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 29 Mar 2018 12:30:31 +0000 (14:30 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Sep 2018 11:59:29 +0000 (13:59 +0200)
builder-support/gen-version

index a2ff215567020ef5ef6597aa44c7c635cd093206..7750a78a71f87ec89814fab166bf7be0d7ca2a89 100755 (executable)
@@ -1,8 +1,6 @@
 #!/bin/sh
-
-if [ ! -z "$BUILDER_VERSION" ]; then
-  printf $BUILDER_VERSION
-  echo $BUILDER_VERSION > .version
+if [ ! -z "${BUILDER_VERSION}" ]; then
+  printf ${BUILDER_VERSION}
   exit 0
 fi
 
@@ -12,7 +10,7 @@ DIRTY=""
 git status | grep -q clean || DIRTY='.dirty'
 
 # Special environment variable to signal that we are building a release, as this
-# has consequences for the version number.
+# has condequenses for the version number.
 if [ "${IS_RELEASE}" = "YES" ]; then
   TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
   if [ -n "${TAG}" ]; then
@@ -29,18 +27,35 @@ fi
 # Generate the version number based on the branch
 #
 if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
+  GIT_VERSION=""
   if $(git rev-parse --abbrev-ref HEAD | grep -q 'rel/'); then
     REL_TYPE="$(git rev-parse --abbrev-ref HEAD | cut -d/ -f 2 | cut -d- -f 1)"
-    VERSION="$(git describe --match=${REL_TYPE}-* --tags --dirty=.dirty | cut -d- -f 2-)"
-  else
-    GIT_VERSION=$(git show --no-patch --format=format:%h HEAD)
-    BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/[^[:alnum:]]//g;')"
-    [ "${BRANCH}" = ".master" ] && BRANCH=''
-    VERSION="0.0${BRANCH}.${PDNS_BUILD_NUMBER}g${GIT_VERSION}${DIRTY}"
+    GIT_VERSION="$(git describe --match=${REL_TYPE}-* --tags | cut -d- -f2-)"
   fi
-  echo "$VERSION" > .version
-elif [ -f .version ]; then
-  VERSION="$(cat .version)"
+
+  LAST_TAG="$(echo ${GIT_VERSION} | cut -d- -f1)"
+  COMMITS_SINCE_TAG="$(echo ${GIT_VERSION} | cut -d- -f2)"
+  GIT_HASH="$(echo ${GIT_VERSION} | cut -d- -f3)"
+
+  if [ -z "${GIT_VERSION}" ]; then
+    LAST_TAG=0.0.0
+    COMMITS_SINCE_TAG="$(git rev-list --count 12c868770afc20b6cc0da439d881105151d557dd..HEAD 2> /dev/null)"
+    GIT_HASH="$(git rev-parse HEAD | cut -c1-10 2> /dev/null)"
+  fi
+
+  BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/[^[:alnum:]]//g;')"
+  [ "${BRANCH}" = ".master" ] && BRANCH=''
+
+  TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
+  if [ -n "${TAG}" ]; then # We're exactly on a tag
+    COMMITS_SINCE_TAG="0"
+    GIT_HASH="g$(git show --no-patch --format=format:%h HEAD 2>/dev/null)"
+    if [ -z "$GIT_HASH" ]; then
+      GIT_HASH="g$(git show --format=format:%h HEAD | head -n1)"
+    fi
+  fi
+
+  VERSION="${LAST_TAG}.${COMMITS_SINCE_TAG}${BRANCH}.${GIT_HASH}${DIRTY}"
 fi
 
 printf $VERSION