Commit 26ada829 authored by Filippos Giannakos's avatar Filippos Giannakos
Browse files

Merge branch 'feature-fix-release-version' into develop

parents d1b6f868 37a64ad0
#Changelog for feature-fix-release-version
* Fix debian tag when finishing release
* Strip rc from version when ending a release
* Make bump version modular.
* Add a _bump version function without any validation checking. Use the new
validate_version to perform the validation.
* Split version validation from version generating
...@@ -7,7 +7,7 @@ logging.basicConfig() ...@@ -7,7 +7,7 @@ logging.basicConfig()
from argparse import ArgumentParser from argparse import ArgumentParser
os.environ["GIT_PYTHON_TRACE"] = "full" os.environ["GIT_PYTHON_TRACE"] = "full"
from devflow import utils, versioning from devflow import utils, versioning, RC_RE
from devflow.version import __version__ from devflow.version import __version__
from devflow.autopkg import call from devflow.autopkg import call
from devflow.ui import query_action, query_user, query_yes_no from devflow.ui import query_action, query_user, query_yes_no
...@@ -302,11 +302,17 @@ class GitManager(object): ...@@ -302,11 +302,17 @@ class GitManager(object):
upstream_branch = self.get_branch("release", version) upstream_branch = self.get_branch("release", version)
debian_branch = self.get_debian_branch("release", version) debian_branch = self.get_debian_branch("release", version)
tag = upstream_branch tag = upstream_branch
debial_tag = "debian/" + tag debian_tag = "debian/" + tag
edit_action = partial(self.edit_changelog, upstream_branch, "develop") edit_action = partial(self.edit_changelog, upstream_branch, "develop")
self.check_edit_changelog(edit_action, args, default=True) self.check_edit_changelog(edit_action, args, default=True)
vcs = utils.get_vcs_info()
release_version = versioning.get_base_version(vcs)
if re.match('.*'+RC_RE, release_version):
new_version = re.sub(RC_RE, '', release_version)
versioning._bump_version(new_version, vcs)
#merge to master #merge to master
self._merge_branches(master, upstream_branch) self._merge_branches(master, upstream_branch)
self._merge_branches(debian_master, debian_branch) self._merge_branches(debian_master, debian_branch)
...@@ -315,7 +321,7 @@ class GitManager(object): ...@@ -315,7 +321,7 @@ class GitManager(object):
repo.git.checkout(master) repo.git.checkout(master)
repo.git.tag("%s" % tag) repo.git.tag("%s" % tag)
repo.git.checkout(debian) repo.git.checkout(debian)
repo.git.tag("%s" % debian) repo.git.tag("%s" % debian_tag)
#merge release changes to upstream #merge release changes to upstream
self.merge_branches(upstream, upstream_branch, args, default=True) self.merge_branches(upstream, upstream_branch, args, default=True)
......
...@@ -73,6 +73,36 @@ def get_base_version(vcs_info): ...@@ -73,6 +73,36 @@ def get_base_version(vcs_info):
f.close() f.close()
return lines[0] return lines[0]
def validate_version(base_version, vcs_info):
branch = vcs_info.branch
brnorm = utils.normalize_branch_name(branch)
btypestr = utils.get_branch_type(branch)
try:
btype = BRANCH_TYPES[btypestr]
except KeyError:
allowed_branches = ", ".join(x for x in BRANCH_TYPES.keys())
raise ValueError("Malformed branch name '%s', cannot classify as one "
"of %s" % (btypestr, allowed_branches))
if btype.versioned:
try:
bverstr = brnorm.split("-")[1]
except IndexError:
# No version
raise ValueError("Branch name '%s' should contain version" %
branch)
# Check that version is well-formed
if not re.match(VERSION_RE, bverstr):
raise ValueError("Malformed version '%s' in branch name '%s'" %
(bverstr, branch))
m = re.match(btype.allowed_version_re, base_version)
if not m or (btype.versioned and m.groupdict()["bverstr"] != bverstr):
raise ValueError("Base version '%s' unsuitable for branch name '%s'" %
(base_version, branch))
def python_version(base_version, vcs_info, mode): def python_version(base_version, vcs_info, mode):
"""Generate a Python distribution version following devtools conventions. """Generate a Python distribution version following devtools conventions.
...@@ -191,36 +221,11 @@ def python_version(base_version, vcs_info, mode): ...@@ -191,36 +221,11 @@ def python_version(base_version, vcs_info, mode):
""" """
validate_version(base_version, vcs_info)
branch = vcs_info.branch branch = vcs_info.branch
brnorm = utils.normalize_branch_name(branch)
btypestr = utils.get_branch_type(branch) btypestr = utils.get_branch_type(branch)
#this cannot fail
try: btype = BRANCH_TYPES[btypestr]
btype = BRANCH_TYPES[btypestr]
except KeyError:
allowed_branches = ", ".join(x for x in BRANCH_TYPES.keys())
raise ValueError("Malformed branch name '%s', cannot classify as one "
"of %s" % (btypestr, allowed_branches))
if btype.versioned:
try:
bverstr = brnorm.split("-")[1]
except IndexError:
# No version
raise ValueError("Branch name '%s' should contain version" %
branch)
# Check that version is well-formed
if not re.match(VERSION_RE, bverstr):
raise ValueError("Malformed version '%s' in branch name '%s'" %
(bverstr, branch))
m = re.match(btype.allowed_version_re, base_version)
if not m or (btype.versioned and m.groupdict()["bverstr"] != bverstr):
raise ValueError("Base version '%s' unsuitable for branch name '%s'" %
(base_version, branch))
if mode not in ["snapshot", "release"]: if mode not in ["snapshot", "release"]:
raise ValueError("Specified mode '%s' should be one of 'snapshot' or " raise ValueError("Specified mode '%s' should be one of 'snapshot' or "
...@@ -407,17 +412,9 @@ def bump_version_main(): ...@@ -407,17 +412,9 @@ def bump_version_main():
sys.stdout.write("usage: %s version\n" % sys.argv[0]) sys.stdout.write("usage: %s version\n" % sys.argv[0])
def bump_version(new_version): def _bump_version(new_version, v):
"""Set new base version to base version file and commit"""
v = utils.get_vcs_info()
mode = utils.get_build_mode()
# Check that new base version is valid
python_version(new_version, v, mode)
repo = utils.get_repository() repo = utils.get_repository()
toplevel = repo.working_dir toplevel = repo.working_dir
old_version = get_base_version(v) old_version = get_base_version(v)
sys.stdout.write("Current base version is '%s'\n" % old_version) sys.stdout.write("Current base version is '%s'\n" % old_version)
...@@ -440,6 +437,16 @@ def bump_version(new_version): ...@@ -440,6 +437,16 @@ def bump_version(new_version):
sys.stdout.write("Update version file and commited\n") sys.stdout.write("Update version file and commited\n")
def bump_version(new_version):
"""Set new base version to base version file and commit"""
v = utils.get_vcs_info()
# Check that new base version is valid
validate_version(new_version, v)
_bump_version(new_version, v)
def main(): def main():
v = utils.get_vcs_info() v = utils.get_vcs_info()
b = get_base_version(v) b = get_base_version(v)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment