blob: b8748af1588d03e4dd839f46197e74b5bca7ae0c [file] [log] [blame]
Damjan Marion39d88cc2022-04-29 19:09:38 +02001#!/usr/bin/env bash
Ed Warnickecb9cada2015-12-08 15:45:58 -07002
Dave Barach8d0f2f02018-03-12 09:31:36 -04003# 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:
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15
Thomas F Herbert20a29c72016-10-13 18:36:50 -040016path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
17
18cd "$path"
19
Damjan Marionc06eeb02017-04-18 15:26:39 +020020if [ -f .version ]; then
Thomas F Herbert20a29c72016-10-13 18:36:50 -040021 vstring=$(cat .version)
22else
Nick Brown0faf3882021-09-27 12:11:23 +010023 vstring=$(git describe --long --match "v*")
Damjan Marionc06eeb02017-04-18 15:26:39 +020024 if [ $? != 0 ]; then
25 exit 1
Thomas F Herbert20a29c72016-10-13 18:36:50 -040026 fi
27fi
28
29TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
30ADD=$(echo ${vstring} | cut -s -d- -f2)
Andrew Yourtchenko10603322020-07-02 12:39:00 +000031POINT=$(echo ${TAG} | cut -d. -f3)
32
33# if this is a "implicit zeroth" release (e.g. 19.08), check if we need to add ".0"
34# to fix the artifact versioning sorting
35if [ -z "${POINT}" ]; then
36 # verify that we are not:
37 # - directly on the XX.YY tag (then ADD will equal "0" by its construction)
38 # - not on any of the builds past "-rc[123]" but before releases - then ADD will be "rc[123]"
Andrew Yourtchenkobc312472020-09-22 16:04:35 +000039 if [ "${ADD}" != "0" -a "${ADD}" != "rc0" -a "${ADD}" != "rc1" -a "${ADD}" != "rc2" -a "${ADD}" != "rc3" -a "${ADD}" != "rc4" ]; then
Andrew Yourtchenko10603322020-07-02 12:39:00 +000040 TAG="${TAG}.0"
41 fi
42fi
Thomas F Herbert20a29c72016-10-13 18:36:50 -040043
44git rev-parse 2> /dev/null
45if [ $? == 0 ]; then
Andrew Yourtchenko10603322020-07-02 12:39:00 +000046 CMT=$(git describe --dirty --long --match 'v*'| cut -s -d- -f3,4)
Thomas F Herbert20a29c72016-10-13 18:36:50 -040047else
48 CMT=$(echo ${vstring} | cut -s -d- -f3,4)
49fi
50CMTR=$(echo $CMT | sed 's/-/_/')
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
Damjan Marion4e6be682016-05-16 15:55:36 +020052if [ -n "${BUILD_NUMBER}" ]; then
53 BLD="~b${BUILD_NUMBER}"
54fi
55
Ed Warnickecb9cada2015-12-08 15:45:58 -070056if [ "$1" = "rpm-version" ]; then
57 echo ${TAG}
58 exit
59fi
60
61if [ "$1" = "rpm-release" ]; then
Andrew Yourtchenko10603322020-07-02 12:39:00 +000062 [ "${ADD}" = "0" ] && echo release && exit
Thomas F Herbert20a29c72016-10-13 18:36:50 -040063 echo ${ADD}${CMTR:+~${CMTR}}${BLD}
Ed Warnickecb9cada2015-12-08 15:45:58 -070064 exit
65fi
66
Andrew Yourtchenko10603322020-07-02 12:39:00 +000067 if [ "${ADD}" != "0" ]; then
Thomas F Herbert20a29c72016-10-13 18:36:50 -040068 if [ "$1" = "rpm-string" ]; then
69 echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD}
70 else
71 echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD}
72 fi
73 else
Damjan Marion926c7062017-01-21 00:04:30 +010074 echo ${TAG}-release
Ed Warnickecb9cada2015-12-08 15:45:58 -070075fi