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.

37 lines
1.1 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. def semver(ver):
  10. if re.match('v[0-9]+\.[0-9]+',ver) is None:
  11. ver="v0.0"
  12. #raise argparse.ArgumentTypeError('--version must be a semantic version number with major, minor and patch numbers')
  13. return ver
  14. if __name__ == "__main__":
  15. parser = argparse.ArgumentParser()
  16. parser.add_argument("--version", help="Version number to bump, e.g.: v1.0.0", required=True, type=semver)
  17. args = parser.parse_args()
  18. found = re.match('(v[0-9]+\.[0-9]+)(\.(.+))?', args.version)
  19. majorminorprefix = found.group(1)
  20. patch = found.group(3)
  21. if patch is None:
  22. patch = "0-new"
  23. if re.match('[0-9]+$',patch) is None:
  24. patchfound = re.match('([0-9]+)',patch)
  25. patch = int(patchfound.group(1))
  26. else:
  27. patch = int(patch) + 1
  28. print("{0}.{1}".format(majorminorprefix, patch))