enable npm and maven prerelease version syntax
This commit is contained in:
parent
48c317f07b
commit
6fae3372f2
@ -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:
|
||||||
@ -35,6 +35,7 @@ class SemVer(object):
|
|||||||
self.major_branches = self._setting_to_array('major_branches')
|
self.major_branches = self._setting_to_array('major_branches')
|
||||||
self.minor_branches = self._setting_to_array('minor_branches')
|
self.minor_branches = self._setting_to_array('minor_branches')
|
||||||
self.patch_branches = self._setting_to_array('patch_branches')
|
self.patch_branches = self._setting_to_array('patch_branches')
|
||||||
|
self.get_branches()
|
||||||
|
|
||||||
def _setting_to_array(self, setting):
|
def _setting_to_array(self, setting):
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
@ -44,7 +45,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 +76,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 +104,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,npm=False,maven=False,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,20 +19,33 @@ 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()
|
||||||
|
# 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:
|
if dot:
|
||||||
b = b.replace('/','.')
|
branch = branch.replace('/','.')
|
||||||
return b
|
return branch
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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('-n', '--npm', help='NPM sytle pre-release version', action='store_true', dest='npm', 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)
|
parser.add_argument('-b', '--build-number', help='Build number, used in pre-releases', default=0)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -73,7 +53,7 @@ def main():
|
|||||||
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.npm,args.maven,args.dot))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try: main()
|
try: main()
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user