3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
20 if [ -f .version ]; then
21 vstring=$(cat .version)
23 vstring=$(git describe --long)
29 TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
30 ADD=$(echo ${vstring} | cut -s -d- -f2)
31 POINT=$(echo ${TAG} | cut -d. -f3)
33 # during make pkg-rpm vstring ends up being vXX.YY, which is not what we expect. Fix it up.
34 if [ -z "${ADD}" ]; then
38 # if this is a "implicit zeroth" release (e.g. 19.08), check if we need to add ".0"
39 # to fix the artifact versioning sorting
40 if [ -z "${POINT}" ]; then
41 # verify that we are not:
42 # - directly on the XX.YY tag (then ADD will equal "0" by its construction)
43 # - not on any of the builds past "-rc[123]" but before releases - then ADD will be "rc[123]"
44 if [ "${ADD}" != "0" -a "${ADD}" != "rc0" -a "${ADD}" != "rc1" -a "${ADD}" != "rc2" -a "${ADD}" != "rc3" -a "${ADD}" != "rc4" ]; then
49 git rev-parse 2> /dev/null
51 CMT=$(git describe --dirty --long --match 'v*'| cut -s -d- -f3,4)
53 CMT=$(echo ${vstring} | cut -s -d- -f3,4)
55 CMTR=$(echo $CMT | sed 's/-/_/')
57 if [ -n "${BUILD_NUMBER}" ]; then
58 BLD="~b${BUILD_NUMBER}"
61 if [ "$1" = "rpm-version" ]; then
66 if [ "$1" = "rpm-release" ]; then
67 [ "${ADD}" = "0" ] && echo release && exit
68 echo ${ADD}${CMTR:+~${CMTR}}${BLD}
72 if [ "${ADD}" != "0" ]; then
73 if [ "$1" = "rpm-string" ]; then
74 echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD}
76 echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD}