taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

bump-version (1985B)


      1 #!/usr/bin/env python3
      2 
      3 import argparse
      4 import re
      5 import subprocess
      6 import sys
      7 import textwrap
      8 
      9 
     10 def shget(cmd):
     11     return subprocess.run(
     12         cmd, shell=True, encoding="utf-8", capture_output=True
     13     ).stdout.strip()
     14 
     15 
     16 parser = argparse.ArgumentParser(description="Bump the taler-rust version.")
     17 
     18 parser.add_argument("new_version")
     19 parser.add_argument("--dry", action="store_true")
     20 
     21 args = parser.parse_args()
     22 
     23 new_version = args.new_version
     24 dry = args.dry
     25 
     26 version = sys.argv[1]
     27 
     28 # Bump version of "debian/changelog"
     29 
     30 with open("debian/changelog") as deb_changelog:
     31     while True:
     32         line = deb_changelog.readline()
     33         if line == "":
     34             break
     35         if line.strip() == "":
     36             continue
     37         m = re.match(r".*\((.*)\).*", line)
     38         break
     39 
     40 deb_current_version = m.group(1)
     41 deb_bump = " [!]" if deb_current_version != version else ""
     42 
     43 print(f"debian/control: {deb_current_version} -> {version}{deb_bump}")
     44 
     45 if not dry and deb_current_version != version:
     46     name = shget("git config user.name")
     47     email = shget("git config user.email")
     48     date = shget("date -R")
     49     entry_r = f"""\
     50     taler-rust ({new_version}) unstable; urgency=low
     51 
     52       * Release version {new_version}
     53 
     54      -- {name} <{email}>  {date}
     55     """
     56     entry = textwrap.dedent(entry_r)
     57     with open("debian/changelog") as f:
     58         old_changelog = f.read()
     59     new_changelog = entry + "\n" + old_changelog
     60     with open("debian/changelog", "w") as f:
     61         f.write(new_changelog)
     62 
     63 # Bump version in Cargo.toml
     64 
     65 with open("Cargo.toml") as f:
     66     contents = f.read()
     67 cargo_pat = r'version.*=.*"(.*)"'
     68 m = re.search(cargo_pat, contents)
     69 cargo_current_version = m.group(1)
     70 
     71 new_contents = re.sub(cargo_pat, f'version = "{new_version}"', contents, count=1)
     72 cargo_bump = " [!]" if cargo_current_version != version else ""
     73 print(f"Cargo.toml: {cargo_current_version} -> {version}{cargo_bump}")
     74 
     75 if not dry:
     76     with open("Cargo.toml", "w") as f:
     77         f.write(new_contents)