Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Dave Barach | 8d0f2f0 | 2018-03-12 09:31:36 -0400 | [diff] [blame] | 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: |
| 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 Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 16 | path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) |
| 17 | |
| 18 | cd "$path" |
| 19 | |
Damjan Marion | c06eeb0 | 2017-04-18 15:26:39 +0200 | [diff] [blame] | 20 | if [ -f .version ]; then |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 21 | vstring=$(cat .version) |
| 22 | else |
Andrew Yourtchenko | 1060332 | 2020-07-02 12:39:00 +0000 | [diff] [blame^] | 23 | vstring=$(git describe --long) |
Damjan Marion | c06eeb0 | 2017-04-18 15:26:39 +0200 | [diff] [blame] | 24 | if [ $? != 0 ]; then |
| 25 | exit 1 |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 26 | fi |
| 27 | fi |
| 28 | |
| 29 | TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//') |
| 30 | ADD=$(echo ${vstring} | cut -s -d- -f2) |
Andrew Yourtchenko | 1060332 | 2020-07-02 12:39:00 +0000 | [diff] [blame^] | 31 | POINT=$(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 |
| 35 | if [ -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]" |
| 39 | if [ "${ADD}" != "0" -a "${ADD}" != "rc0" -a "${ADD}" != "rc1" -a "${ADD}" != "rc2" ]; then |
| 40 | TAG="${TAG}.0" |
| 41 | fi |
| 42 | fi |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 43 | |
| 44 | git rev-parse 2> /dev/null |
| 45 | if [ $? == 0 ]; then |
Andrew Yourtchenko | 1060332 | 2020-07-02 12:39:00 +0000 | [diff] [blame^] | 46 | CMT=$(git describe --dirty --long --match 'v*'| cut -s -d- -f3,4) |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 47 | else |
| 48 | CMT=$(echo ${vstring} | cut -s -d- -f3,4) |
| 49 | fi |
| 50 | CMTR=$(echo $CMT | sed 's/-/_/') |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | |
Damjan Marion | 4e6be68 | 2016-05-16 15:55:36 +0200 | [diff] [blame] | 52 | if [ -n "${BUILD_NUMBER}" ]; then |
| 53 | BLD="~b${BUILD_NUMBER}" |
| 54 | fi |
| 55 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | if [ "$1" = "rpm-version" ]; then |
| 57 | echo ${TAG} |
| 58 | exit |
| 59 | fi |
| 60 | |
| 61 | if [ "$1" = "rpm-release" ]; then |
Andrew Yourtchenko | 1060332 | 2020-07-02 12:39:00 +0000 | [diff] [blame^] | 62 | [ "${ADD}" = "0" ] && echo release && exit |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 63 | echo ${ADD}${CMTR:+~${CMTR}}${BLD} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | exit |
| 65 | fi |
| 66 | |
Andrew Yourtchenko | 1060332 | 2020-07-02 12:39:00 +0000 | [diff] [blame^] | 67 | if [ "${ADD}" != "0" ]; then |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 68 | 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 Marion | 926c706 | 2017-01-21 00:04:30 +0100 | [diff] [blame] | 74 | echo ${TAG}-release |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | fi |