import subprocess import sys if subprocess.run( ["git", "branch", "--show-current"], stdout=subprocess.PIPE).stdout.decode().strip() != "main": print("WARNING! Not on the main branch.") subprocess.run(["git", "pull", "--rebase"]) p = subprocess.run(["git", "describe", "--abbrev=0"], stdout=subprocess.PIPE) describe = p.stdout.decode().strip() old_version = describe[1:].split("-")[0].split(".") if len(old_version) == 2: [major, minor] = old_version [major, minor] = map(int, [major, minor]) patch = 0 else: [major, minor, patch] = old_version [major, minor, patch] = map(int, [major, minor, patch]) print(f"old version: {major}.{minor}.{patch}") update_type = None if sys.argv[1] in ["patch", "minor", "major"]: update_type = sys.argv[1] elif sys.argv[1] == "auto": p = subprocess.run( ["git", "log", "--pretty=format:%s", f"{describe}..HEAD"], stdout=subprocess.PIPE) commits = p.stdout.decode() update_type = "patch" for commit in commits.split("\n"): if commit.startswith("feat:"): update_type = "minor" elif commit.startswith("feat!:") or commit.startswith("fix!:"): update_type = "major" print(f"commits:\n{commits}") else: print("ERROR: invalid bump type") sys.exit(1) p = subprocess.run( ["cargo", "release", "--workspace", "--execute", update_type]) if p.returncode != 0: print("ERROR: cargo release returned nonzero exit code") sys.exit(1)