diff --git a/scripts/release.py b/scripts/release.py index 65c2a88b1..a05830c10 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,23 +1,26 @@ #!/usr/bin/env python3 import os +import re import subprocess def create_tag(): - subprocess.check_call(["git", "fetch", "--all", "--tags"]) # fetch remote tags + subprocess.check_call(["git", "fetch", "--all", "--tags"]) # create new tag as per current release stream = os.popen('git describe --abbrev=0 --tags') current_tag = stream.read().strip() - # TODO(Xueyan): the current parsing is buggy, if the main version number is a two-digit number. - # You need parse the string, e.g., the first string is 'v', and after 'v', there should be - # two numbers seperated by a '.' - if current_tag[0] != 'v': - raise Exception("The tag name should start with v") - major_version = int(current_tag[1]) - minor_version = int(current_tag[3]) - q, r = divmod(minor_version + 1, 10) - return "v{}.{}".format(major_version + q, r) + + if not re.match("^v[0-9]+[.][0-9]", current_tag): + raise Exception("Error: tag name does not follow expected pattern.") + + version = current_tag[1:].split('.') + + major_version = int(version[0]) + minor_version = int(version[1]) + increment, new_minor_version = divmod(minor_version + 1, 10) + + return f"v{major_version + increment}.{new_minor_version}" def build_binary(): @@ -40,13 +43,13 @@ def main(): raise Exception('ERROR: This script should be run in the root folder of the project.') tag_name = create_tag() - title = "Perses {}".format(tag_name) + title = f"Perses {tag_name}" # get built binary path jar = build_binary() # release - release_command = ['hub', 'release', 'create', '-a', jar, '-m', title, tag_name] + release_command = ['hub', 'release', 'create', '--browse', f"--attach={jar}", f'--message={title}', tag_name] pipe = None subprocess.check_call(