|
| 1 | +# updates the version number in the __about__.py file |
| 2 | +import subprocess |
| 3 | + |
| 4 | + |
| 5 | +def update_version(version_type): |
| 6 | + with open("src/api/__about__.py", "r") as f: |
| 7 | + version = f.read().split("=")[1].replace('"', "").strip() |
| 8 | + patch_version = version.split(".")[2] |
| 9 | + minor_version = version.split(".")[1] |
| 10 | + major_version = version.split(".")[0] |
| 11 | + if version_type == "major": |
| 12 | + major_version = str(int(major_version) + 1) |
| 13 | + minor_version = "0" |
| 14 | + patch_version = "0" |
| 15 | + elif version_type == "minor": |
| 16 | + minor_version = str(int(minor_version) + 1) |
| 17 | + patch_version = "0" |
| 18 | + elif version_type == "patch": |
| 19 | + patch_version = str(int(patch_version) + 1) |
| 20 | + else: |
| 21 | + raise ValueError("Invalid version type. Please use major, minor, or patch.") |
| 22 | + with open("src/api/__about__.py", "w") as f: |
| 23 | + new_version = f"{major_version}.{minor_version}.{patch_version}" |
| 24 | + f.write(f'__version__ = "{new_version}"\n') |
| 25 | + return f"v{new_version}" |
| 26 | + |
| 27 | + |
| 28 | +# passes the command line argument to the function |
| 29 | +if __name__ == "__main__": |
| 30 | + import sys |
| 31 | + |
| 32 | + new_version = update_version(sys.argv[1]) |
| 33 | + message = input(f"Version updated to {new_version}. Enter commit message: \n") |
| 34 | + subprocess.run(["git", "add", "."]) |
| 35 | + subprocess.run(["git", "commit", "-m", message.strip()]) |
| 36 | + subprocess.run(["git", "push"]) |
| 37 | + subprocess.run(["git", "tag", "-a", new_version, "-m", new_version]) |
| 38 | + subprocess.run(["git", "push", "origin", new_version]) |
0 commit comments