From 20cf9b2b01b9a79733551dcbf1bca66a2f80862a Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Tue, 16 Jun 2020 15:20:41 -0400 Subject: [PATCH] add docker format support --- semver/get_version.py | 4 ++-- semver/tests.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/semver/get_version.py b/semver/get_version.py index 12ed552..d3cd0d5 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -31,7 +31,7 @@ def get_version(build=0,version_format=None,dot=False): bump_output = p.stdout.read().decode('utf-8').rstrip() next_version = re.search("new_version=([0-9]*.[0-9]*.[0-9]*)", bump_output).group(1) - if version_format == 'npm': + if version_format is 'npm' or 'docker': return "{}-{}.{}".format(next_version,branch.replace('/','-'),build) if version_format == 'maven': qualifier = 'SNAPSHOT' if build == 0 else build @@ -46,7 +46,7 @@ def main(): parser = argparse.ArgumentParser(description='Get Version or Branch.') parser.add_argument('-d', '--dot', help='Switch out / for . to be used in docker tag', action='store_true', dest='dot') parser.add_argument('-D', '--debug', help='Sets logging level to DEBUG', action='store_true', dest='debug', default=False) - parser.add_argument('-f', '--format', help='Format for pre-release version syntax', choices=['npm','maven'], default=None) + parser.add_argument('-f', '--format', help='Format for pre-release version syntax', choices=['npm','maven','docker'], default=None) parser.add_argument('-b', '--build-number', help='Build number, used in pre-releases', default=0) args = parser.parse_args() diff --git a/semver/tests.py b/semver/tests.py index bd08fd4..826029e 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -66,6 +66,11 @@ class TestGetVersion(unittest.TestCase): subprocess.call(['git', 'checkout', '-b', 'patch/branch']) branch = get_version.get_version(version_format='npm') self.assertEqual(branch, "0.0.1-patch-branch.0") + def test_branch_docker_pre_release(self): + create_git_environment() + subprocess.call(['git', 'checkout', '-b', 'patch/branch']) + branch = get_version.get_version(build=2,version_format='npm') + self.assertEqual(branch, "0.0.1-patch-branch.2") def test_branch_maven_pre_release(self): create_git_environment() subprocess.call(['git', 'checkout', '-b', 'minor/branch'])