From 48c317f07bf6f4f1c0d4190e47a2d394d3d74090 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 10:44:19 -0400 Subject: [PATCH 01/17] add extra flags --- semver/get_version.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/semver/get_version.py b/semver/get_version.py index 0535a67..38f659c 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -64,6 +64,10 @@ 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('-n', '--npm', help='NPM sytle pre-release version', action='store_true', dest='npm', default=False) + parser.add_argument('-m', '--maven', help='Maven sytle pre-release version', action='store_true', dest='npm', default=False) + parser.add_argument('-b', '--build-number', help='Build number, used in pre-releases', default=0) + args = parser.parse_args() if args.debug: From 6fae3372f2700967339125b077579afd025795a6 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:01:33 -0400 Subject: [PATCH 02/17] enable npm and maven prerelease version syntax --- semver/__init__.py | 19 ++++-------- semver/get_version.py | 68 +++++++++++++++---------------------------- semver/utils.py | 41 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 58 deletions(-) create mode 100644 semver/utils.py diff --git a/semver/__init__.py b/semver/__init__.py index 987763a..554fa35 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -1,7 +1,7 @@ import argparse import re 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 try: @@ -35,6 +35,7 @@ class SemVer(object): self.major_branches = self._setting_to_array('major_branches') self.minor_branches = self._setting_to_array('minor_branches') self.patch_branches = self._setting_to_array('patch_branches') + self.get_branches() def _setting_to_array(self, setting): config = ConfigParser() @@ -44,7 +45,6 @@ class SemVer(object): return list(filter(bool, [v.strip() for v in value.split(',')])) # based on commit message see what branches are involved in the merge - def get_branches(self): p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE, cwd='.') @@ -76,15 +76,15 @@ class SemVer(object): for prefix in self.major_branches: if prefix == merged_prefix: self.version_type = 'major' - return True + return self.version_type for prefix in self.minor_branches: if prefix == merged_prefix: self.version_type = 'minor' - return True + return self.version_type for prefix in self.patch_branches: if prefix == merged_prefix: self.version_type = 'patch' - return True + return self.version_type return False # setup git settings so we can commit and tag @@ -104,15 +104,6 @@ class SemVer(object): config_file = "" with open(".bumpversion.cfg", "r") as file: 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 logger.debug("Running bumpversion of type: " + self.version_type) diff --git a/semver/get_version.py b/semver/get_version.py index 38f659c..2b143ef 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -1,44 +1,11 @@ import argparse -from semver.logger import logging, logger, console_logger +import re import subprocess -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') +from semver.logger import logging, logger, console_logger +from semver.utils import get_tag_version, get_file_version, DEVNULL +from semver import SemVer -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 - -def get_version(dot=False): +def get_version(build=0,npm=False,maven=False,dot=False): version = get_tag_version() # Get the commit hash of the version @@ -52,20 +19,33 @@ def get_version(dot=False): # do not match return the branch name else return the version if v_hash != c_hash: 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() + # Find the next version + semver = SemVer() + semver.merged_branch = branch + version_type = semver.get_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.stderr.read().decode() + next_version = match = re.search("New version will be '([0-9]*.[0-9]*.[0-9]*)'", bump_output).group(1) + + if npm: + return "{}-{}.{}".format(next_version,branch.replace('/','-'),build) + if maven: + qualifier = 'SNAPSHOT' if build == 0 else build + return "{}-{}-{}".format(next_version,branch.replace('/','-'),qualifier) if dot: - b = b.replace('/','.') - return b + branch = branch.replace('/','.') + return branch return version 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', '--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('-n', '--npm', help='NPM sytle pre-release version', action='store_true', dest='npm', default=False) - parser.add_argument('-m', '--maven', help='Maven sytle pre-release version', action='store_true', dest='npm', default=False) + parser.add_argument('-m', '--maven', help='Maven sytle pre-release version', action='store_true', dest='maven', default=False) parser.add_argument('-b', '--build-number', help='Build number, used in pre-releases', default=0) args = parser.parse_args() @@ -73,7 +53,7 @@ def main(): if args.debug: console_logger.setLevel(logging.DEBUG) - print(get_version(args.dot)) + print(get_version(args.build_number,args.npm,args.maven,args.dot)) if __name__ == '__main__': try: main() diff --git a/semver/utils.py b/semver/utils.py new file mode 100644 index 0000000..88f813b --- /dev/null +++ b/semver/utils.py @@ -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 + From 2c07ef743e693240013d193199800d31ed5dfba6 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:29:37 -0400 Subject: [PATCH 03/17] move to format rather than specific flags --- semver/get_version.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/semver/get_version.py b/semver/get_version.py index 2b143ef..e4d0663 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -5,7 +5,7 @@ from semver.logger import logging, logger, console_logger from semver.utils import get_tag_version, get_file_version, DEVNULL from semver import SemVer -def get_version(build=0,npm=False,maven=False,dot=False): +def get_version(build=0,version_format=None,dot=False): version = get_tag_version() # Get the commit hash of the version @@ -29,9 +29,9 @@ def get_version(build=0,npm=False,maven=False,dot=False): bump_output = p.stderr.read().decode() next_version = match = re.search("New version will be '([0-9]*.[0-9]*.[0-9]*)'", bump_output).group(1) - if npm: + if version_format == 'npm': return "{}-{}.{}".format(next_version,branch.replace('/','-'),build) - if maven: + if version_format == 'maven': qualifier = 'SNAPSHOT' if build == 0 else build return "{}-{}-{}".format(next_version,branch.replace('/','-'),qualifier) if dot: @@ -44,8 +44,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('-n', '--npm', help='NPM sytle pre-release version', action='store_true', dest='npm', default=False) - parser.add_argument('-m', '--maven', help='Maven sytle pre-release version', action='store_true', dest='maven', 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() @@ -53,7 +52,7 @@ def main(): if args.debug: console_logger.setLevel(logging.DEBUG) - print(get_version(args.build_number,args.npm,args.maven,args.dot)) + print(get_version(args.build_number,args.format,args.dot)) if __name__ == '__main__': try: main() From ebe6b60aaf9cbc4ace1368a38e62c8a591df6b2c Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:45:34 -0400 Subject: [PATCH 04/17] update tests --- semver/get_version.py | 1 + semver/tests.py | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/semver/get_version.py b/semver/get_version.py index e4d0663..4bb7f07 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -57,3 +57,4 @@ def main(): if __name__ == '__main__': try: main() except: raise + diff --git a/semver/tests.py b/semver/tests.py index a391131..b32f0ec 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -1,7 +1,7 @@ import unittest, os, subprocess, re, semver 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 = """ [bumpversion] @@ -54,13 +54,23 @@ class TestGetVersion(unittest.TestCase): def test_branch_dotting(self): create_git_environment() 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") def test_branch_dotting_false(self): create_git_environment() 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', 'test/branch']) + branch = get_version.get_version(version_format='npm') + self.assertEqual(branch, "0.0.0-test-branch.0") + def test_branch_maven_pre_release(self): + create_git_environment() + subprocess.call(['git', 'checkout', '-b', 'test/branch']) + branch = get_version.get_version(version_format='npm') + self.assertEqual(branch, "0.0.0-test-branch-SNAPSHOT") def test_get_version_run(self): create_git_environment() val = subprocess.Popen(['python', '../get_version.py', '-d'], stdout=subprocess.PIPE, @@ -72,7 +82,7 @@ class TestGetTagVersion(unittest.TestCase): def test_get_version_tag(self): create_git_environment() subprocess.call(['git', 'tag', '1.0.0']) - tag = get_version.get_tag_version() + tag = utils.get_tag_version() self.assertEqual(tag, "1.0.0") def test_get_version_multiple(self): create_git_environment() @@ -87,7 +97,7 @@ class TestGetTagVersion(unittest.TestCase): subprocess.call(['git', 'tag', '1.1.0']) subprocess.call(['git', 'tag', '1.2.0']) subprocess.call(['git', 'tag', '1.2.1']) - tag = get_version.get_tag_version() + tag = utils.get_tag_version() self.assertEqual(tag, "1.2.1") def test_get_version_out_of_order(self): subprocess.call(['git', 'tag', '0.1.0']) @@ -101,11 +111,11 @@ class TestGetTagVersion(unittest.TestCase): subprocess.call(['git', 'tag', '1.1.7']) subprocess.call(['git', 'tag', '1.2.0']) subprocess.call(['git', 'tag', '0.2.1']) - tag = get_version.get_tag_version() + tag = utils.get_tag_version() self.assertEqual(tag, "8.1.0") def test_default_get_version_tag(self): create_git_environment() - tag = get_version.get_tag_version() + tag = utils.get_tag_version() self.assertEqual(tag, "0.0.0") class TestGetCommitMessageRegex(unittest.TestCase): @@ -145,4 +155,4 @@ if __name__ == "__main__": with open('.bumpversion.cfg', "w") as config: config.write(config_data) unittest.main() - os.chdir("..") \ No newline at end of file + os.chdir("..") From 63386027c13331610eb83d08f96a9639586a34be Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:50:41 -0400 Subject: [PATCH 05/17] update readme --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 109d78b..ce23a3d 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Runs with debug logging. ### 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 @@ -137,6 +137,14 @@ Replaces `/` with `.` in branch names. For example, `feature/test` becomes `feat 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 This repository is also home to a Jenkins shared library to assit in running auto-semver. @@ -168,4 +176,4 @@ pipeline #### runAutoSemver( String _dockerImage_ ) -**dockerImage:** The Docker image and tag to run auto-semver with. By default, it pulls `rightbrainnetworks/auto-semver:latest`. \ No newline at end of file +**dockerImage:** The Docker image and tag to run auto-semver with. By default, it pulls `rightbrainnetworks/auto-semver:latest`. From a3910ed34dbe123ea8305716e029ada453fc2482 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:53:56 -0400 Subject: [PATCH 06/17] update docker file --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e271759..c8bad98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ USER root RUN pip install --upgrade pip RUN yum update -y RUN yum -y remove git -RUN yum -y install https://centos7.iuscommunity.org/ius-release.rpm +RUN yum -y install https://repo.ius.io/ius-release-el7.rpm \ + https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm RUN yum -y install git2u-all #Setup semver From 8ea6ab33253526b8b088c835666371e284271dc4 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 16:57:41 -0400 Subject: [PATCH 07/17] update docker file --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c8bad98..af9c6be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,8 @@ USER root RUN pip install --upgrade pip RUN yum update -y RUN yum -y remove git -RUN yum -y install https://repo.ius.io/ius-release-el7.rpm \ - https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -RUN yum -y install git2u-all +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 git #Setup semver ADD / /semver From 56ee7b103d58ef87cdb8bb4915b038e1d6b02b2f Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:15:54 -0400 Subject: [PATCH 08/17] only look for new version if doing format --- semver/get_version.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/semver/get_version.py b/semver/get_version.py index 4bb7f07..56c9125 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -21,19 +21,19 @@ def get_version(build=0,version_format=None,dot=False): logger.debug("v_hash and c_hash do not match!") branch = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE, stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip() - # Find the next version - semver = SemVer() - semver.merged_branch = branch - version_type = semver.get_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.stderr.read().decode() - next_version = match = re.search("New version will be '([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 version_format: + semver = SemVer() + semver.merged_branch = branch + version_type = semver.get_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.stderr.read().decode() + next_version = match = re.search("New version will be '([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: branch = branch.replace('/','.') return branch From cf7e92bc1d6bc6c2a3d2bc385f37341645b0366c Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:19:00 -0400 Subject: [PATCH 09/17] test inside current docker image --- Jenkinsfile | 4 +--- semver/get_version.py | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cbbd435..cf5378e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,9 +57,7 @@ pipeline { } stage('Test') { agent { - docker { - image "rightbrainnetworks/auto-semver:${env.VERSION}" - } + dockerfile true } steps { diff --git a/semver/get_version.py b/semver/get_version.py index 56c9125..ae64ee1 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -21,19 +21,18 @@ def get_version(build=0,version_format=None,dot=False): logger.debug("v_hash and c_hash do not match!") branch = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE, stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip() - if version_format: - semver = SemVer() - semver.merged_branch = branch - version_type = semver.get_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.stderr.read().decode() - next_version = match = re.search("New version will be '([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) + semver = SemVer() + semver.merged_branch = branch + version_type = semver.get_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.stderr.read().decode() + next_version = match = re.search("New version will be '([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: branch = branch.replace('/','.') return branch From d274dc4f27b43d49c6c95a7e1f2fd667f63ee8e2 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:28:06 -0400 Subject: [PATCH 10/17] change syntax --- semver/get_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semver/get_version.py b/semver/get_version.py index ae64ee1..8562e58 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -26,7 +26,7 @@ def get_version(build=0,version_format=None,dot=False): version_type = semver.get_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.stderr.read().decode() - next_version = match = re.search("New version will be '([0-9]*.[0-9]*.[0-9]*)'", bump_output).group(1) + 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) From 74fe2a324d1ce109ecce3896960bc210e5a1d04a Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:29:40 -0400 Subject: [PATCH 11/17] use output not error --- semver/get_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semver/get_version.py b/semver/get_version.py index 8562e58..61a5436 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -25,7 +25,7 @@ def get_version(build=0,version_format=None,dot=False): semver.merged_branch = branch version_type = semver.get_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.stderr.read().decode() + 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': From 90ad8d0a4aee0ba55f29c614f10167b59bec4012 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:33:13 -0400 Subject: [PATCH 12/17] dont run get_branchs on init --- semver/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/semver/__init__.py b/semver/__init__.py index 554fa35..5a7077e 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -35,7 +35,6 @@ class SemVer(object): self.major_branches = self._setting_to_array('major_branches') self.minor_branches = self._setting_to_array('minor_branches') self.patch_branches = self._setting_to_array('patch_branches') - self.get_branches() def _setting_to_array(self, setting): config = ConfigParser() From 682ab6e7cc28fb3de9227ad9c53a16102daf51c6 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:43:14 -0400 Subject: [PATCH 13/17] add debug lines --- semver/get_version.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/semver/get_version.py b/semver/get_version.py index 61a5436..0a4533b 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -23,7 +23,9 @@ def get_version(build=0,version_format=None,dot=False): 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)) 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) From 0265f52eb3b4e326b53fe64e0316282683e9a838 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:44:58 -0400 Subject: [PATCH 14/17] set agent back to how it was --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cf5378e..cbbd435 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,7 +57,9 @@ pipeline { } stage('Test') { agent { - dockerfile true + docker { + image "rightbrainnetworks/auto-semver:${env.VERSION}" + } } steps { From fbdc7af4df790f86f6e501c7e17d2c58564a10f5 Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:48:27 -0400 Subject: [PATCH 15/17] only dry run version if the branch is of a version type --- semver/get_version.py | 17 +++++++++-------- semver/tests.py | 8 ++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/semver/get_version.py b/semver/get_version.py index 0a4533b..12ed552 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -26,15 +26,16 @@ def get_version(build=0,version_format=None,dot=False): logger.debug("merged branch is: {}".format(semver.merged_branch)) version_type = semver.get_version_type() logger.debug("version type is: {}".format(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_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 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: branch = branch.replace('/','.') return branch diff --git a/semver/tests.py b/semver/tests.py index b32f0ec..523a5b6 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -63,14 +63,14 @@ class TestGetVersion(unittest.TestCase): self.assertEqual(branch, "test/branch") def test_branch_npm_pre_release(self): create_git_environment() - subprocess.call(['git', 'checkout', '-b', 'test/branch']) + subprocess.call(['git', 'checkout', '-b', 'patch/branch']) branch = get_version.get_version(version_format='npm') - self.assertEqual(branch, "0.0.0-test-branch.0") + self.assertEqual(branch, "0.0.0-patch-branch.0") def test_branch_maven_pre_release(self): create_git_environment() - subprocess.call(['git', 'checkout', '-b', 'test/branch']) + subprocess.call(['git', 'checkout', '-b', 'minor/branch']) branch = get_version.get_version(version_format='npm') - self.assertEqual(branch, "0.0.0-test-branch-SNAPSHOT") + self.assertEqual(branch, "0.0.0-minor-branch-SNAPSHOT") def test_get_version_run(self): create_git_environment() val = subprocess.Popen(['python', '../get_version.py', '-d'], stdout=subprocess.PIPE, From 160758942c8afebb8c4ee4ccea400f578ca7893e Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:50:25 -0400 Subject: [PATCH 16/17] more tests --- semver/tests.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/semver/tests.py b/semver/tests.py index 523a5b6..c24b2c0 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -69,8 +69,13 @@ class TestGetVersion(unittest.TestCase): def test_branch_maven_pre_release(self): create_git_environment() subprocess.call(['git', 'checkout', '-b', 'minor/branch']) - branch = get_version.get_version(version_format='npm') + branch = get_version.get_version(version_format='maven') self.assertEqual(branch, "0.0.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") def test_get_version_run(self): create_git_environment() val = subprocess.Popen(['python', '../get_version.py', '-d'], stdout=subprocess.PIPE, From da2f6358db52a309d18c69c3664804daa0b2466a Mon Sep 17 00:00:00 2001 From: Derek DeJonghe Date: Mon, 15 Jun 2020 17:51:05 -0400 Subject: [PATCH 17/17] fix assert --- semver/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/semver/tests.py b/semver/tests.py index c24b2c0..382383c 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -65,12 +65,12 @@ class TestGetVersion(unittest.TestCase): create_git_environment() subprocess.call(['git', 'checkout', '-b', 'patch/branch']) branch = get_version.get_version(version_format='npm') - self.assertEqual(branch, "0.0.0-patch-branch.0") + 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.0.0-minor-branch-SNAPSHOT") + 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'])