diff options
author | Mik Mueller | 2022-08-07 14:13:17 +0200 |
---|---|---|
committer | Mik Mueller | 2022-08-07 14:13:17 +0200 |
commit | 2e946b3bf40f94a764bf385d200bd302223dab72 (patch) | |
tree | 5ccc6566755e59ebae2899ba73813e0e62b6cd1a | |
parent | 5f86f3fee034ff8bb8464e91cc1b55ff5bd1d62f (diff) | |
download | aur-2e946b3bf40f94a764bf385d200bd302223dab72.tar.gz |
Add update-version.py
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | update_version.py | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 05c6d4d4c97b..471133a35970 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ !.gitignore !.SRCINFO !PKGBUILD +!update_version.py diff --git a/update_version.py b/update_version.py new file mode 100644 index 000000000000..45601200740c --- /dev/null +++ b/update_version.py @@ -0,0 +1,29 @@ +#!/usr/bin/python +# This file is used to update the version number +# The SemVer (https://semver.org) versioning system is used. +import re +import sys + +pkgbuild_path = "./PKGBUILD" + +with open(pkgbuild_path, "r") as main_go: + content = main_go.read() + old_version = content.split("pkgver=")[1].split("\n")[0] + print(f"Found old version in {pkgbuild_path}: {old_version}") + +# Get the second command-line argument +if len(sys.argv) != 2: + print("Exactly one argument (new semver-version) is required but {} were given.".format(len(sys.argv)-1)) + quit(1) +else: + VERSION = sys.argv[1] + +if not re.match(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$", VERSION): + print( + f"\x1b[31mThe version: '{VERSION}' is not a valid SemVer version.\x1b[0m") + quit() + +with open(pkgbuild_path, "w") as main_go: + main_go.write(content.replace(old_version, VERSION)) + +print(f"Version has been changed from '{old_version}' -> '{VERSION}'") |