You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB

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