From d2577d38eb0834251ad268e57adee855b21bee4f Mon Sep 17 00:00:00 2001 From: Bob Ball Date: Fri, 26 Aug 2016 13:14:09 +0100 Subject: [PATCH] Make branding based on the branch, to remove the PLUGIN_REVISION variable By checking which branch we are on, we can automatically determine the revision based on the length of history between the root of the branch and this change. Normally (and in development environments) this isn't guaranteed as you can create arbitrary branches (e.g. branch a and branch b could have the same merge base) but if run against code checked out from github will give a consistent version number Change-Id: I6eff6befce1408dac144dd7dfb3f3055820960a8 --- Makefile | 2 ++ branding.inc | 8 ++++++-- get_plugin_version.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 get_plugin_version.sh diff --git a/Makefile b/Makefile index c7cf7bb..de8e552 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ BRANDING=branding.inc include ${BRANDING} +PLUGIN_VERSION:=$(shell ./get_plugin_version.sh ${BRANDING} | cut -d' ' -f1) +PLUGIN_REVISION:=$(shell ./get_plugin_version.sh ${BRANDING} | cut -d' ' -f2) RPM_NAME=${PLUGIN_NAME}-${PLUGIN_VERSION}-${PLUGIN_VERSION}.${PLUGIN_REVISION}-1.noarch.rpm BUILDROOT=BUILD diff --git a/branding.inc b/branding.inc index ac83121..48712a2 100644 --- a/branding.inc +++ b/branding.inc @@ -1,5 +1,9 @@ HYPERVISOR_NAME=XenServer HYPERVISOR_LOWER=xenserver PLUGIN_NAME=fuel-plugin-xenserver -PLUGIN_VERSION=3.91 -PLUGIN_REVISION=3 + +PLUGIN_BRANCHES="9.0 8.0 7.0 6.1" +PLUGIN_VERSION_6_1=1.0 +PLUGIN_VERSION_7_0=2.0 +PLUGIN_VERSION_8_0=3.1 +PLUGIN_VERSION_9_0=4.0 diff --git a/get_plugin_version.sh b/get_plugin_version.sh new file mode 100755 index 0000000..7e29654 --- /dev/null +++ b/get_plugin_version.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -eu + +# Source the branding file +. ${1} + +# Find shortest delta +my_merge_base=$(git merge-base HEAD origin/master) + +shortest_branch=master +for branch in $PLUGIN_BRANCHES; do + + # Verify that the named branch actually exists + set +e + git rev-parse --verify origin/$branch >/dev/null 2>/dev/null + branch_test_exit_code=$? + set -e + if [ $branch_test_exit_code -gt 0 ]; then + continue + fi + + branch_merge_base=$(git merge-base origin/master origin/$branch) + + if [ "$branch_merge_base" == "$my_merge_base" ]; then + shortest_branch=$branch + fi +done + +if [ $shortest_branch == 'master' ]; then + shortest_branch=$(echo $PLUGIN_BRANCHES | cut -d' ' -f1) + var_name=PLUGIN_VERSION_${shortest_branch//./_} + branch_major=$(echo ${!var_name} | cut -d'.' -f1) + branch_major=${branch_major}.90 + branch_minor=$(git rev-list HEAD --count) +else + var_name=PLUGIN_VERSION_${shortest_branch//./_} + branch_merge_base=$(git merge-base origin/master origin/$shortest_branch) + branch_major=${!var_name} + branch_minor=$(git rev-list HEAD ^$branch_merge_base --count) +fi +echo $branch_major $branch_minor