[8.0][build] Fix rc openstack versions

Fix using openstack beta and rc tags as versions

Change-Id: I968b6f62a9a700dd6304b8de1083866430e415c4
Partial-Bug: #1510026
This commit is contained in:
Dmitry Burmistrov 2015-10-26 15:28:35 +03:00 committed by Artem Silenkov
parent 6e1b82b205
commit 5b61266e19
3 changed files with 84 additions and 4 deletions

View File

@ -22,8 +22,12 @@ main () {
local version=`head -1 ${_debianpath}/debian/changelog | sed 's|^.*(||;s|).*$||' | awk -F "-" '{print $1}'`
# Get version number from the latest git tag for openstack packages
[ "$IS_OPENSTACK" == "true" ] && version=`git -C $_srcpath describe --abbrev=0`
# TODO: Deal with openstack RC tags like 2015.1.0rc1
# It breaks debian version comparison. Need to replace 'rc' with '~rc'
# Deal with PyPi versions like 2015.1.0rc1
# It breaks version comparison
# Change it to 2015.1.0~rc1
local convert_version_py="$(dirname $(readlink -e $0))/convert-version.py"
version=$(python ${convert_version_py} --tag ${version})
local binpackagenames="`cat ${_debianpath}/debian/control | grep ^Package | cut -d' ' -f 2 | tr '\n' ' '`"
local epochnumber=`head -1 ${_debianpath}/debian/changelog | grep -o "(.:" | sed 's|(||'`
local distro=`head -1 ${_debianpath}/debian/changelog | awk -F'[ ;]' '{print $3}'`

View File

@ -39,8 +39,12 @@ This package provides the %{-n*} kernel modules
if [ "$IS_OPENSTACK" == "true" ] ; then
# Get version number from the latest git tag for openstack packages
local version=`git -C $_srcpath describe --abbrev=0`
# TODO: Deal with openstack RC tags like 2015.1.0rc1
# It breaks rpm version comparison.
# Deal with PyPi versions like 2015.1.0rc1
# It breaks version comparison
# Change it to 2015.1.0~rc1
local convert_version_py="$(dirname $(readlink -e $0))/convert-version.py"
version=$(python ${convert_version_py} --tag ${version})
# Get revision number as commit count for src+spec projects
local _src_commit_count=`git -C $_srcpath rev-list --no-merges origin/${SOURCE_BRANCH} | wc -l`
local _spec_commit_count=`git -C $_specpath rev-list --no-merges origin/${SPEC_BRANCH} | wc -l`

72
perestroika/convert-version.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
##
# Convert pip style alpha/beta/rc/dev versions to the ones suitable for a
# package manager.
# Does not modify the conventional 3-digit version numbers.
# Examples:
# 1.2.3.0a4 -> 1.2.3~a4
# 1.2.3rc1 -> 1.2.3~rc1
# 1.2.3 -> 1.2.3
import argparse
from pkg_resources import parse_version
import re
def strip_leading_zeros(s):
return re.sub(r"^0+([0-9]+)", r"\1", s)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-t', '--tag', dest='tag', action='store', type=str,
help='PyPi version tag', required=True, default='0'
)
params, other_params = parser.parse_known_args()
pip_ver = params.tag
# drop dashed part from version string because
# it represents a patch level of given version
pip_ver = pip_ver.split('-')[0]
# add leading 1 if tag is starting from letter
if re.match(r"^[a-zA-Z]", pip_ver):
pip_ver = '1' + pip_ver
# parse_version converts string '12.0.0.0rc1'
# to touple ('00000012', '*c', '00000001', '*final')
# details:
# http://galaxy-dist.readthedocs.org/en/latest/lib/pkg_resources.html
pip_ver_parts = parse_version(pip_ver)
_ver = True
pkg_ver_part = []
pkg_alpha = ""
pkg_rev_part = []
for part in pip_ver_parts:
if part == "*final":
continue
if re.match(r"[*a-z]", part):
_ver = False
pkg_alpha = re.sub(r"^\*", "~", part)
continue
if _ver:
pkg_ver_part.append(strip_leading_zeros(part))
else:
pkg_rev_part.append(strip_leading_zeros(part))
# replace 'c' and '@' with 'rc' and 'dev' at pkg_alpha
pkg_alpha = pkg_alpha.replace('c', 'rc')
pkg_alpha = pkg_alpha.replace('@', 'dev')
# expand version to three items
while (len(pkg_ver_part) < 3):
pkg_ver_part.append('0')
print('.'.join(pkg_ver_part) + pkg_alpha + '.'.join(pkg_rev_part))
if __name__ == "__main__":
main()