github.com/vipernet-xyz/tendermint-core@v0.32.0/scripts/release_management/bump-semver.py (about)

     1  #!/usr/bin/env python
     2  
     3  # Bump the release number of a semantic version number and print it. --version is required.
     4  # Version is
     5  # - vA.B.C, in which case vA.B.C+1 will be returned
     6  # - vA.B.C-devorwhatnot in which case vA.B.C will be returned
     7  # - vA.B in which case vA.B.0 will be returned
     8  
     9  import re
    10  import argparse
    11  import sys
    12  
    13  
    14  def semver(ver):
    15    if re.match('v[0-9]+\.[0-9]+',ver) is None:
    16      ver="v0.0"
    17      #raise argparse.ArgumentTypeError('--version must be a semantic version number with major, minor and patch numbers')
    18    return ver
    19  
    20  
    21  def get_tendermint_version():
    22    """Extracts the current Tendermint version from version/version.go"""
    23    pattern = re.compile(r"TMCoreSemVer = \"(?P<version>([0-9.]+)+)\"")
    24    with open("version/version.go", "rt") as version_file:
    25      for line in version_file:
    26        m = pattern.search(line)
    27        if m:
    28          return m.group('version')
    29  
    30    return None
    31  
    32  
    33  if __name__ == "__main__":
    34    parser = argparse.ArgumentParser()
    35    parser.add_argument("--version", help="Version number to bump, e.g.: v1.0.0", required=True, type=semver)
    36    args = parser.parse_args()
    37  
    38    found = re.match('(v[0-9]+\.[0-9]+)(\.(.+))?', args.version)
    39    majorminorprefix = found.group(1)
    40    patch = found.group(3)
    41    if patch is None:
    42      patch = "0-new"
    43  
    44    if re.match('[0-9]+$',patch) is None:
    45      patchfound = re.match('([0-9]+)',patch)
    46      patch = int(patchfound.group(1))
    47    else:
    48      patch = int(patch) + 1
    49  
    50    expected_version = "{0}.{1}".format(majorminorprefix, patch)
    51    # if we're doing a release
    52    if expected_version != "v0.0.0":
    53      cur_version = get_tendermint_version()
    54      if not cur_version:
    55        print("Failed to obtain Tendermint version from version/version.go")
    56        sys.exit(1)
    57      expected_version_noprefix = expected_version.lstrip("v")
    58      if expected_version_noprefix != "0.0.0" and expected_version_noprefix != cur_version:
    59        print("Expected version/version.go#TMCoreSemVer to be {0}, but was {1}".format(expected_version_noprefix, cur_version))
    60        sys.exit(1)
    61  
    62    print(expected_version)