version-at-commit.sh uses '.dev' instead of '.pre'
[arvados.git] / build / version-at-commit.sh
1 #!/bin/bash
2
3 set -e -o pipefail
4 commit="$1"
5 versionglob="[0-9].[0-9]*.[0-9]*"
6 devsuffix=".dev"
7
8 if ! git describe --exact-match --match "$versionglob" "$commit" 2>/dev/null; then
9     if git merge-base --is-ancestor "$commit" origin/master; then
10         # x.(y+1).0.preTIMESTAMP, where x.y.z is the newest version that does not contain $commit
11         v=$(git tag | grep -vFf <(git tag --contains "$commit") | sort -Vr | head -n1 | perl -pe 's/\.(\d+)\.\d+/".".($1+1).".0"/e')
12     else
13         # x.y.(z+1).preTIMESTAMP, where x.y.z is the latest released ancestor of $commit
14         v=$(git describe --abbrev=0 --match "$versionglob" "$commit" | perl -pe 's/(\d+)$/$1+1/e')
15     fi
16     isodate=$(TZ=UTC git log -n1 --format=%cd --date=iso "$commit")
17     ts=$(TZ=UTC date --date="$isodate" "+%Y%m%d%H%M%S")
18     echo "${v}${devsuffix}${ts}"
19 fi