Merge pull request #45 from RightBrain-Networks/feature/pre-releases
Feature/pre releases
This commit is contained in:
		@ -6,8 +6,8 @@ USER root
 | 
				
			|||||||
RUN pip install --upgrade pip
 | 
					RUN pip install --upgrade pip
 | 
				
			||||||
RUN yum update -y
 | 
					RUN yum update -y
 | 
				
			||||||
RUN yum -y remove git
 | 
					RUN yum -y remove git
 | 
				
			||||||
RUN yum -y install  https://centos7.iuscommunity.org/ius-release.rpm
 | 
					RUN yum -y install https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm
 | 
				
			||||||
RUN yum -y install  git2u-all
 | 
					RUN yum -y install git
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Setup semver
 | 
					#Setup semver
 | 
				
			||||||
ADD / /semver
 | 
					ADD / /semver
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							@ -125,7 +125,7 @@ Runs with debug logging.
 | 
				
			|||||||
<a name="semver_get_version"></a>
 | 
					<a name="semver_get_version"></a>
 | 
				
			||||||
### semver_get_version
 | 
					### semver_get_version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The `semver_get_version` command returns the version number if the `semver` command exited `0`. If `semver` exited anything else, `semver_get_version` will return the branch name.
 | 
					The `semver_get_version` command returns the version number if the `semver` command exited `0`. If `semver` exited anything else, `semver_get_version` will return the branch name, or a pre-release version if format is specified
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Flags
 | 
					#### Flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -137,6 +137,14 @@ Replaces `/` with `.` in branch names. For example, `feature/test` becomes `feat
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Runs with debug logging.
 | 
					Runs with debug logging.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`-f`/`--format` `(npm|maven)`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Formats the output for a pre-release version for a specific repository type. For example, `feature/test` becomes `0.1.0-feature-test-SNAPSHOT` for maven with no build number, or `0.1.0-feature-test.0` for maven with no build number.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`-b`/`--build-number` `number`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Provides a build number for pre-release versions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Jenkins Shared Library
 | 
					### Jenkins Shared Library
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This repository is also home to a Jenkins shared library to assit in running auto-semver.
 | 
					This repository is also home to a Jenkins shared library to assit in running auto-semver.
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
from semver.get_version import get_tag_version
 | 
					from semver.utils import get_tag_version
 | 
				
			||||||
from semver.logger import logging, logger, console_logger
 | 
					from semver.logger import logging, logger, console_logger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try: 
 | 
					try: 
 | 
				
			||||||
@ -44,7 +44,6 @@ class SemVer(object):
 | 
				
			|||||||
        return list(filter(bool, [v.strip() for v in value.split(',')]))
 | 
					        return list(filter(bool, [v.strip() for v in value.split(',')]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # based on commit message see what branches are involved in the merge
 | 
					    # based on commit message see what branches are involved in the merge
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    def get_branches(self):
 | 
					    def get_branches(self):
 | 
				
			||||||
        p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE,
 | 
					        p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE,
 | 
				
			||||||
                             cwd='.')
 | 
					                             cwd='.')
 | 
				
			||||||
@ -76,15 +75,15 @@ class SemVer(object):
 | 
				
			|||||||
            for prefix in self.major_branches:
 | 
					            for prefix in self.major_branches:
 | 
				
			||||||
                if prefix == merged_prefix:
 | 
					                if prefix == merged_prefix:
 | 
				
			||||||
                    self.version_type = 'major'
 | 
					                    self.version_type = 'major'
 | 
				
			||||||
                    return True
 | 
					                    return self.version_type
 | 
				
			||||||
            for prefix in self.minor_branches:
 | 
					            for prefix in self.minor_branches:
 | 
				
			||||||
                if prefix == merged_prefix:
 | 
					                if prefix == merged_prefix:
 | 
				
			||||||
                    self.version_type = 'minor'
 | 
					                    self.version_type = 'minor'
 | 
				
			||||||
                    return True
 | 
					                    return self.version_type
 | 
				
			||||||
            for prefix in self.patch_branches:
 | 
					            for prefix in self.patch_branches:
 | 
				
			||||||
                if prefix == merged_prefix:
 | 
					                if prefix == merged_prefix:
 | 
				
			||||||
                    self.version_type = 'patch'
 | 
					                    self.version_type = 'patch'
 | 
				
			||||||
                    return True
 | 
					                    return self.version_type
 | 
				
			||||||
        return False
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # setup git settings so we can commit and tag
 | 
					    # setup git settings so we can commit and tag
 | 
				
			||||||
@ -104,15 +103,6 @@ class SemVer(object):
 | 
				
			|||||||
        config_file = ""
 | 
					        config_file = ""
 | 
				
			||||||
        with open(".bumpversion.cfg", "r") as file:
 | 
					        with open(".bumpversion.cfg", "r") as file:
 | 
				
			||||||
            config_file = file.read()
 | 
					            config_file = file.read()
 | 
				
			||||||
        # Update .bumpconfig
 | 
					 | 
				
			||||||
        #pattern = re.compile("current_version = [0-9.]*")
 | 
					 | 
				
			||||||
        #current_config = re.search(pattern, config_file)
 | 
					 | 
				
			||||||
        #if current_config:
 | 
					 | 
				
			||||||
            #config_file.replace(current_config.group(0), "current_version = " + get_tag_version())
 | 
					 | 
				
			||||||
        #else:
 | 
					 | 
				
			||||||
            #config_file.replace("[bumpversion]","[bumpversion]\ncurrent_version = " + get_tag_version())
 | 
					 | 
				
			||||||
        #with open(".bumpversion.cfg", "w") as file:
 | 
					 | 
				
			||||||
            #file.write(config_file)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # version repo
 | 
					        # version repo
 | 
				
			||||||
        logger.debug("Running bumpversion of type: " + self.version_type)
 | 
					        logger.debug("Running bumpversion of type: " + self.version_type)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,44 +1,11 @@
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
from semver.logger import logging, logger, console_logger
 | 
					import re
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
try:
 | 
					from semver.logger import logging, logger, console_logger
 | 
				
			||||||
    from configparser import ConfigParser
 | 
					from semver.utils import get_tag_version, get_file_version, DEVNULL
 | 
				
			||||||
except ImportError:
 | 
					from semver import SemVer
 | 
				
			||||||
    # Python < 3
 | 
					 | 
				
			||||||
    from ConfigParser import ConfigParser
 | 
					 | 
				
			||||||
try:
 | 
					 | 
				
			||||||
    from subprocess import DEVNULL # py3k
 | 
					 | 
				
			||||||
except ImportError:
 | 
					 | 
				
			||||||
    import os
 | 
					 | 
				
			||||||
    DEVNULL = open(os.devnull, 'wb')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_tag_version():
 | 
					def get_version(build=0,version_format=None,dot=False):
 | 
				
			||||||
    config = ConfigParser()
 | 
					 | 
				
			||||||
    config.read('./.bumpversion.cfg')
 | 
					 | 
				
			||||||
    tag_expression = config.get('bumpversion','tag_name').replace('{new_version}','[0-9]*.[0-9]*.[0-9]*')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    logger.debug("Tag expression: " + str(tag_expression))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Default version is `0.0.0` or what is found in 
 | 
					 | 
				
			||||||
    version = get_file_version(config)
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    # If a version is found in tags, use that the lastest tagged version
 | 
					 | 
				
			||||||
    tagged_versions = subprocess.Popen(['git','tag','--sort=v:refname', '-l',tag_expression],
 | 
					 | 
				
			||||||
        stdout=subprocess.PIPE, stderr=DEVNULL, cwd=".").stdout.read().decode('utf-8').rstrip().split('\n')
 | 
					 | 
				
			||||||
    if len(tagged_versions) > 0 and tagged_versions[-1] != "":
 | 
					 | 
				
			||||||
        version = tagged_versions[-1]
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    logger.debug("Tag Version: " + str(version))
 | 
					 | 
				
			||||||
    return version
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def get_file_version(config):
 | 
					 | 
				
			||||||
    version = config.get('bumpversion','current_version')
 | 
					 | 
				
			||||||
    if not version:
 | 
					 | 
				
			||||||
        config.set('bumpversion', 'current_version', '0.0.0')
 | 
					 | 
				
			||||||
        version = '0.0.0'
 | 
					 | 
				
			||||||
    return version
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def get_version(dot=False):
 | 
					 | 
				
			||||||
    version = get_tag_version()
 | 
					    version = get_tag_version()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Get the commit hash of the version 
 | 
					    # Get the commit hash of the version 
 | 
				
			||||||
@ -52,11 +19,26 @@ def get_version(dot=False):
 | 
				
			|||||||
    # do not match return the branch name else return the version
 | 
					    # do not match return the branch name else return the version
 | 
				
			||||||
    if v_hash != c_hash:
 | 
					    if v_hash != c_hash:
 | 
				
			||||||
        logger.debug("v_hash and c_hash do not match!")
 | 
					        logger.debug("v_hash and c_hash do not match!")
 | 
				
			||||||
        b = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE,
 | 
					        branch = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE,
 | 
				
			||||||
                            stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip()
 | 
					                            stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip()
 | 
				
			||||||
 | 
					        semver = SemVer()
 | 
				
			||||||
 | 
					        semver.merged_branch = branch
 | 
				
			||||||
 | 
					        logger.debug("merged branch is: {}".format(semver.merged_branch))
 | 
				
			||||||
 | 
					        version_type = semver.get_version_type()
 | 
				
			||||||
 | 
					        logger.debug("version type is: {}".format(version_type))
 | 
				
			||||||
 | 
					        if version_type:
 | 
				
			||||||
 | 
					            p = subprocess.Popen(['bumpversion', '--dry-run', '--verbose', '--current-version', get_tag_version(), version_type], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='.')
 | 
				
			||||||
 | 
					            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':
 | 
				
			||||||
 | 
					                return "{}-{}.{}".format(next_version,branch.replace('/','-'),build)
 | 
				
			||||||
 | 
					            if version_format == 'maven':
 | 
				
			||||||
 | 
					                qualifier = 'SNAPSHOT' if build == 0 else build
 | 
				
			||||||
 | 
					                return "{}-{}-{}".format(next_version,branch.replace('/','-'),qualifier)
 | 
				
			||||||
        if dot:
 | 
					        if dot:
 | 
				
			||||||
            b = b.replace('/','.')
 | 
					            branch = branch.replace('/','.')
 | 
				
			||||||
        return b
 | 
					        return branch
 | 
				
			||||||
    return version
 | 
					    return version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,13 +46,17 @@ def main():
 | 
				
			|||||||
    parser = argparse.ArgumentParser(description='Get Version or Branch.')
 | 
					    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', '--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('-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('-b', '--build-number', help='Build number, used in pre-releases', default=0)
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if args.debug:
 | 
					    if args.debug:
 | 
				
			||||||
        console_logger.setLevel(logging.DEBUG)
 | 
					        console_logger.setLevel(logging.DEBUG)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    print(get_version(args.dot))
 | 
					    print(get_version(args.build_number,args.format,args.dot))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    try: main()
 | 
					    try: main()
 | 
				
			||||||
    except: raise
 | 
					    except: raise
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
import unittest, os, subprocess, re, semver
 | 
					import unittest, os, subprocess, re, semver
 | 
				
			||||||
from semver.logger import logging, logger, console_logger
 | 
					from semver.logger import logging, logger, console_logger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from semver import get_version, NO_MERGE_FOUND, GET_COMMIT_MESSAGE
 | 
					from semver import get_version, utils, NO_MERGE_FOUND, GET_COMMIT_MESSAGE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config_data = """
 | 
					config_data = """
 | 
				
			||||||
[bumpversion]
 | 
					[bumpversion]
 | 
				
			||||||
@ -54,12 +54,27 @@ class TestGetVersion(unittest.TestCase):
 | 
				
			|||||||
    def test_branch_dotting(self):
 | 
					    def test_branch_dotting(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
        subprocess.call(['git', 'checkout', '-b', 'test/branch'])
 | 
					        subprocess.call(['git', 'checkout', '-b', 'test/branch'])
 | 
				
			||||||
        branch = get_version.get_version(True)
 | 
					        branch = get_version.get_version(dot=True)
 | 
				
			||||||
        self.assertEqual(branch, "test.branch")
 | 
					        self.assertEqual(branch, "test.branch")
 | 
				
			||||||
    def test_branch_dotting_false(self):
 | 
					    def test_branch_dotting_false(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
        subprocess.call(['git', 'checkout', '-b', 'test/branch'])
 | 
					        subprocess.call(['git', 'checkout', '-b', 'test/branch'])
 | 
				
			||||||
        branch = get_version.get_version(False)
 | 
					        branch = get_version.get_version(dot=False)
 | 
				
			||||||
 | 
					        self.assertEqual(branch, "test/branch")
 | 
				
			||||||
 | 
					    def test_branch_npm_pre_release(self):
 | 
				
			||||||
 | 
					        create_git_environment()
 | 
				
			||||||
 | 
					        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_maven_pre_release(self):
 | 
				
			||||||
 | 
					        create_git_environment()
 | 
				
			||||||
 | 
					        subprocess.call(['git', 'checkout', '-b', 'minor/branch'])
 | 
				
			||||||
 | 
					        branch = get_version.get_version(version_format='maven')
 | 
				
			||||||
 | 
					        self.assertEqual(branch, "0.1.0-minor-branch-SNAPSHOT")
 | 
				
			||||||
 | 
					    def test_branch_maven_bad_branch(self):
 | 
				
			||||||
 | 
					        create_git_environment()
 | 
				
			||||||
 | 
					        subprocess.call(['git', 'checkout', '-b', 'test/branch'])
 | 
				
			||||||
 | 
					        branch = get_version.get_version(version_format='maven')
 | 
				
			||||||
        self.assertEqual(branch, "test/branch")
 | 
					        self.assertEqual(branch, "test/branch")
 | 
				
			||||||
    def test_get_version_run(self):
 | 
					    def test_get_version_run(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
@ -72,7 +87,7 @@ class TestGetTagVersion(unittest.TestCase):
 | 
				
			|||||||
    def test_get_version_tag(self):
 | 
					    def test_get_version_tag(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
        subprocess.call(['git', 'tag', '1.0.0'])
 | 
					        subprocess.call(['git', 'tag', '1.0.0'])
 | 
				
			||||||
        tag = get_version.get_tag_version()
 | 
					        tag = utils.get_tag_version()
 | 
				
			||||||
        self.assertEqual(tag, "1.0.0")
 | 
					        self.assertEqual(tag, "1.0.0")
 | 
				
			||||||
    def test_get_version_multiple(self):
 | 
					    def test_get_version_multiple(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
@ -87,7 +102,7 @@ class TestGetTagVersion(unittest.TestCase):
 | 
				
			|||||||
        subprocess.call(['git', 'tag', '1.1.0'])
 | 
					        subprocess.call(['git', 'tag', '1.1.0'])
 | 
				
			||||||
        subprocess.call(['git', 'tag', '1.2.0'])
 | 
					        subprocess.call(['git', 'tag', '1.2.0'])
 | 
				
			||||||
        subprocess.call(['git', 'tag', '1.2.1'])
 | 
					        subprocess.call(['git', 'tag', '1.2.1'])
 | 
				
			||||||
        tag = get_version.get_tag_version()
 | 
					        tag = utils.get_tag_version()
 | 
				
			||||||
        self.assertEqual(tag, "1.2.1")
 | 
					        self.assertEqual(tag, "1.2.1")
 | 
				
			||||||
    def test_get_version_out_of_order(self):
 | 
					    def test_get_version_out_of_order(self):
 | 
				
			||||||
        subprocess.call(['git', 'tag', '0.1.0'])
 | 
					        subprocess.call(['git', 'tag', '0.1.0'])
 | 
				
			||||||
@ -101,11 +116,11 @@ class TestGetTagVersion(unittest.TestCase):
 | 
				
			|||||||
        subprocess.call(['git', 'tag', '1.1.7'])
 | 
					        subprocess.call(['git', 'tag', '1.1.7'])
 | 
				
			||||||
        subprocess.call(['git', 'tag', '1.2.0'])
 | 
					        subprocess.call(['git', 'tag', '1.2.0'])
 | 
				
			||||||
        subprocess.call(['git', 'tag', '0.2.1'])
 | 
					        subprocess.call(['git', 'tag', '0.2.1'])
 | 
				
			||||||
        tag = get_version.get_tag_version()
 | 
					        tag = utils.get_tag_version()
 | 
				
			||||||
        self.assertEqual(tag, "8.1.0")
 | 
					        self.assertEqual(tag, "8.1.0")
 | 
				
			||||||
    def test_default_get_version_tag(self):
 | 
					    def test_default_get_version_tag(self):
 | 
				
			||||||
        create_git_environment()
 | 
					        create_git_environment()
 | 
				
			||||||
        tag = get_version.get_tag_version()
 | 
					        tag = utils.get_tag_version()
 | 
				
			||||||
        self.assertEqual(tag, "0.0.0")
 | 
					        self.assertEqual(tag, "0.0.0")
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
class TestGetCommitMessageRegex(unittest.TestCase):
 | 
					class TestGetCommitMessageRegex(unittest.TestCase):
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										41
									
								
								semver/utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								semver/utils.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					from semver.logger import logging, logger, console_logger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
					    from configparser import ConfigParser
 | 
				
			||||||
 | 
					except ImportError:
 | 
				
			||||||
 | 
					    # Python < 3
 | 
				
			||||||
 | 
					    from ConfigParser import ConfigParser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
					    from subprocess import DEVNULL # py3k
 | 
				
			||||||
 | 
					except ImportError:
 | 
				
			||||||
 | 
					    import os
 | 
				
			||||||
 | 
					    DEVNULL = open(os.devnull, 'wb')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_tag_version():
 | 
				
			||||||
 | 
					    config = ConfigParser()
 | 
				
			||||||
 | 
					    config.read('./.bumpversion.cfg')
 | 
				
			||||||
 | 
					    tag_expression = config.get('bumpversion','tag_name').replace('{new_version}','[0-9]*.[0-9]*.[0-9]*')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logger.debug("Tag expression: " + str(tag_expression))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Default version is `0.0.0` or what is found in 
 | 
				
			||||||
 | 
					    version = get_file_version(config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # If a version is found in tags, use that the lastest tagged version
 | 
				
			||||||
 | 
					    tagged_versions = subprocess.Popen(['git','tag','--sort=v:refname', '-l',tag_expression],
 | 
				
			||||||
 | 
					        stdout=subprocess.PIPE, stderr=DEVNULL, cwd=".").stdout.read().decode('utf-8').rstrip().split('\n')
 | 
				
			||||||
 | 
					    if len(tagged_versions) > 0 and tagged_versions[-1] != "":
 | 
				
			||||||
 | 
					        version = tagged_versions[-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logger.debug("Tag Version: " + str(version))
 | 
				
			||||||
 | 
					    return version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_file_version(config):
 | 
				
			||||||
 | 
					    version = config.get('bumpversion','current_version')
 | 
				
			||||||
 | 
					    if not version:
 | 
				
			||||||
 | 
					        config.set('bumpversion', 'current_version', '0.0.0')
 | 
				
			||||||
 | 
					        version = '0.0.0'
 | 
				
			||||||
 | 
					    return version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user