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
This commit is contained in:
Bob Ball 2016-08-26 13:14:09 +01:00
parent 08ca10db7e
commit d2577d38eb
3 changed files with 49 additions and 2 deletions

View File

@ -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

View File

@ -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

41
get_plugin_version.sh Executable file
View File

@ -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