X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/32d4f9f58a9669d32fc846e49b08e41c5df9d299..3faf9753f50715a635ebaba790564880e61fa035:/build/version-at-commit.sh diff --git a/build/version-at-commit.sh b/build/version-at-commit.sh index 2f514c82da..50b1e300e7 100755 --- a/build/version-at-commit.sh +++ b/build/version-at-commit.sh @@ -1,17 +1,43 @@ #!/bin/bash +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 set -e -o pipefail commit="$1" versionglob="[0-9].[0-9]*.[0-9]*" +devsuffix="~dev" -if ! git describe --exact-match --match "$versionglob" "$commit" 2>/dev/null; then - if git merge-base --is-ancestor "$commit" origin/master; then - # x.(y+1).0.preTIMESTAMP, where x.y.z is the newest version that does not contain $commit - v=$(git tag | grep -vFf <(git tag --contains "$commit") | sort -Vr | head -n1 | perl -pe 's/\.(\d+)\.\d+/".".($1+1).".0"/e') - else - # x.y.(z+1).preTIMESTAMP, where x.y.z is the latest released ancestor of $commit - v=$(git describe --abbrev=0 --match "$versionglob" "$commit" | perl -pe 's/(\d+)$/$1+1/e') - fi - ts=$(TZ=UTC git log -n1 --format=%cd --date="format-local:%Y%m%d%H%M%S" "$commit") - echo "$v.pre$ts" +# automatically assign *development* version +# +# handles the following cases: +# +# * commit is on main or a development branch, the nearest tag is older +# than commit where this branch joins main. +# -> take greatest version tag in repo X.Y.Z and assign X.(Y+1).0 +# +# * commit is on a release branch, the nearest tag is newer +# than the commit where this branch joins main. +# -> take nearest tag X.Y.Z and assign X.Y.(Z+1) + +# 1. get the nearest tag with 'git describe' +# 2. get the merge base between this commit and main +# 3. if the tag is an ancestor of the merge base, +# (tag is older than merge base) increment minor version +# else, tag is newer than merge base, so increment point version + +nearest_tag=$(git describe --tags --abbrev=0 --match "$versionglob" "$commit") +merge_base=$(git merge-base origin/main "$commit") + +if git merge-base --is-ancestor "$nearest_tag" "$merge_base" ; then + # x.(y+1).0~devTIMESTAMP, where x.y.z is the newest version that does not contain $commit + # grep reads the list of tags (-f) that contain $commit and filters them out (-v) + # this prevents a newer tag from retroactively changing the versions of everything before it + v=$(git tag | grep -vFf <(git tag --contains "$merge_base") | sort -Vr | head -n1 | perl -pe 's/(\d+)\.(\d+)\.\d+.*/"$1.".($2+1).".0"/e') +else + # x.y.(z+1)~devTIMESTAMP, where x.y.z is the latest released ancestor of $commit + v=$(echo $nearest_tag | perl -pe 's/(\d+)$/$1+1/e') fi +isodate=$(TZ=UTC git log -n1 --format=%cd --date=iso "$commit") +ts=$(TZ=UTC date --date="$isodate" "+%Y%m%d%H%M%S") +echo "${v}${devsuffix}${ts}"