Skip to content

Commit

Permalink
Script for upgrading version (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysimonson committed Apr 3, 2022
1 parent c448725 commit 9638603
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions scripts/update_version.py
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

import re
import sys
import subprocess

VERSION_MATCHER = re.compile(r'^version = "([^"]+)\.([^"]+)\.([^"]+)"$')

def run(args, cwd="."):
print("%s => %s" % (cwd, args))
subprocess.check_call(args, cwd=cwd)

def update_version(path, new_version):
with open(path, "r") as f:
contents = f.read().splitlines()

in_package = False

for i, line in enumerate(contents):
if line.startswith("["):
in_package = line == "[package]"
elif in_package:
match = VERSION_MATCHER.match(line)

if match:
old_version = tuple([int(x) for x in match.groups()])
assert new_version > old_version, "New version should be greater than the old version"
contents[i] = 'version = "{}"'.format(".".join(str(x) for x in new_version))

with open(path, "w") as f:
f.write("\n".join(contents))

def main():
if len(sys.argv) < 2:
raise Exception("No version specified")

try:
new_version = tuple([int(x) for x in sys.argv[1].split(".")])
assert len(new_version) == 3
except:
raise Exception("Invalid version specification")

update_version("Cargo.toml", new_version)

run(["make", "check", "test"])

# a github action will pickup this tag push and create a release
new_version_str = "v{}".format(".".join(str(x) for x in new_version))
run(["git", "commit", "-a", "-m", new_version_str])
run(["git", "tag", "-a", new_version_str, "-m", new_version_str])
run(["git", "push", "origin", new_version_str])
run(["cargo", "publish"])

if __name__ == "__main__":
main()

0 comments on commit 9638603

Please sign in to comment.