From 64a3a5c40ae7762b2c68697f74bce79f5a0eee3c Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Wed, 7 Nov 2018 16:17:30 +0530 Subject: [PATCH] fix: proper semantic version bumping - also included tests for the same Signed-off-by: Ameya Shenoy --- bench/release.py | 33 +++++++++++++++++++++------------ bench/tests/test_init.py | 13 +++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/bench/release.py b/bench/release.py index 60384820..6f005274 100755 --- a/bench/release.py +++ b/bench/release.py @@ -154,34 +154,43 @@ def get_current_version(repo_path, to_branch): def get_bumped_version(version, bump_type): v = semantic_version.Version(version) - if bump_type == 'minor': - v.minor += 1 - v.patch = 0 - v.prerelease = None - - elif bump_type == 'major': + if bump_type == 'major': v.major += 1 v.minor = 0 v.patch = 0 v.prerelease = None - elif bump_type == 'patch': - v.patch += 1 + elif bump_type == 'minor': + v.minor += 1 + v.patch = 0 v.prerelease = None + elif bump_type == 'patch': + if v.prerelease == (): + v.patch += 1 + v.prerelease = None + + elif len(v.prerelease) == 2: + v.prerelease = () + elif bump_type == 'stable': # remove pre-release tag v.prerelease = None elif bump_type == 'prerelease': if v.prerelease == (): - v.prerelease = ('beta',) - - if len(v.prerelease)==1: + v.patch += 1 v.prerelease = ('beta', '1') - else: + + elif len(v.prerelease) == 2: v.prerelease = ('beta', str(int(v.prerelease[1]) + 1)) + else: + raise ("Something wen't wrong while doing a prerelease") + + else: + raise ("bump_type not amongst [major, minor, patch, prerelease]") + return str(v) def set_version(repo_path, version, to_branch): diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 380a7edf..0920bf63 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -6,6 +6,7 @@ import bench.utils import bench.app import bench.config.common_site_config import bench.cli +from bench.release import get_bumped_version bench.cli.from_command_line = True @@ -20,6 +21,18 @@ class TestBenchInit(unittest.TestCase): if os.path.exists(bench_path): shutil.rmtree(bench_path, ignore_errors=True) + def test_semantic_version(self): + self.assertEqual( get_bumped_version('11.0.4', 'major'), '12.0.0' ) + self.assertEqual( get_bumped_version('11.0.4', 'minor'), '11.1.0' ) + self.assertEqual( get_bumped_version('11.0.4', 'patch'), '11.0.5' ) + self.assertEqual( get_bumped_version('11.0.4', 'prerelease'), '11.0.5-beta.1' ) + + self.assertEqual( get_bumped_version('11.0.5-beta.22', 'major'), '12.0.0' ) + self.assertEqual( get_bumped_version('11.0.5-beta.22', 'minor'), '11.1.0' ) + self.assertEqual( get_bumped_version('11.0.5-beta.22', 'patch'), '11.0.5' ) + self.assertEqual( get_bumped_version('11.0.5-beta.22', 'prerelease'), '11.0.5-beta.23' ) + + def test_init(self, bench_name="test-bench", **kwargs): self.init_bench(bench_name, **kwargs)