File: gen-version

package info (click to toggle)
pdns-recursor 4.1.11-1+deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,936 kB
  • sloc: cpp: 54,211; javascript: 26,587; sh: 11,872; makefile: 453; xml: 37
file content (46 lines) | stat: -rwxr-xr-x 1,387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

if [ ! -z "$BUILDER_VERSION" ]; then
  printf $BUILDER_VERSION
  echo $BUILDER_VERSION > .version
  exit 0
fi

VERSION="unknown"

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.
if [ "${IS_RELEASE}" = "YES" ]; then
  TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
  if [ -n "${TAG}" ]; then
    # We're on a tag
    echo "${TAG}${DIRTY}" > .version
    printf "${TAG}${DIRTY}"
    exit 0
  fi
  echo 'This is not a tag, either tag this commit or do not set $IS_RELEASE' >&2
  exit 1
fi

#
# Generate the version number based on the branch
#
if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
  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}"
  fi
  echo "$VERSION" > .version
elif [ -f .version ]; then
  VERSION="$(cat .version)"
fi

printf $VERSION