|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import subprocess |
| 3 | +import re |
| 4 | + |
| 5 | +# print changelog |
| 6 | +current_tag = subprocess.run( |
| 7 | + ["git", "describe", "--tags", "--abbrev=0"], capture_output=True, text=True |
| 8 | +).stdout.strip() |
| 9 | +if current_tag == "": |
| 10 | + # os.system("git log HEAD --oneline") |
| 11 | + interval = "HEAD" |
| 12 | +else: |
| 13 | + print("current tag: %s" % current_tag) |
| 14 | + interval = "%s..HEAD" % current_tag |
| 15 | + |
| 16 | +print( |
| 17 | + "CHANGELOG:\n\n%s\n" |
| 18 | + % subprocess.run( |
| 19 | + ["git", "log", interval, "--oneline"], capture_output=True, text=True |
| 20 | + ).stdout.strip() |
| 21 | +) |
| 22 | + |
| 23 | +version_match_re = r'^version\s*=\s*"([^"]+)"$' |
| 24 | + |
| 25 | +with open("Cargo.toml", "rt") as fp: |
| 26 | + manifest = fp.read() |
| 27 | + |
| 28 | +# parse current version and get next from user |
| 29 | +m = re.findall(version_match_re, manifest, re.MULTILINE) |
| 30 | +if len(m) != 1: |
| 31 | + print("could not parse current version from Cargo.toml") |
| 32 | + quit() |
| 33 | + |
| 34 | +current_ver = m[0] |
| 35 | +next_ver = input("current version is %s, enter next: " % current_ver) |
| 36 | + |
| 37 | +# generate new manifest |
| 38 | +result = re.sub( |
| 39 | + version_match_re, 'version = "%s"' % next_ver, manifest, 0, re.MULTILINE |
| 40 | +) |
| 41 | +with open("Cargo.toml", "w+t") as fp: |
| 42 | + fp.write(result) |
| 43 | + |
| 44 | +# commit, push and create new tag |
| 45 | +print("git add Cargo.*") |
| 46 | +print("git commit -m 'releasing version %s'" % next_ver) |
| 47 | +print("git push") |
| 48 | +print("git tag -a v%s -m 'releasing v%s'" % (next_ver, next_ver)) |
| 49 | +print("git push origin v%s" % next_ver) |
| 50 | + |
| 51 | +# print() |
| 52 | +# publish on crates.io |
| 53 | +# print("cargo publish") |
0 commit comments