summaryrefslogtreecommitdiff
path: root/contrib/ci/jobs/4-deb-package/version.sh
blob: a6e740af050f604044abd1a6d85718b5e78a843a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
set -ex

BRANCH=$(git name-rev --name-only HEAD)
if [ -z "${BRANCH}" ]; then
	exit 1
else
        # "Unshallow" our checkout, but only our current branch, and exclude the submodules.
	git fetch --no-recurse-submodules --tags --depth=1000 origin "${BRANCH}"
	RECENT_VERSION_TAG=$(git describe --tags --match 'v*.*.*' --always --abbrev=0 HEAD || exit 1)
	commits="$(git rev-list ${RECENT_VERSION_TAG}..HEAD --count)"
	if [ "${commits}" = "0" ]; then
		git describe --tag HEAD | sed -r 's/^v//' || exit 1
	else
		echo $(echo ${RECENT_VERSION_TAG} | sed -r 's/^v//')-${commits}-$(git rev-parse --short=8 HEAD)
	fi
fi