diff options
author | Fabs | 2024-04-03 10:37:31 +0200 |
---|---|---|
committer | Fabs | 2024-04-03 10:37:31 +0200 |
commit | 0468a219d8654f55e6dccf99aee7d2a6af64d953 (patch) | |
tree | d3aff343bb21053d1b50a09daa0200f3be38f8dd | |
parent | 38d3311b4f68e0c5e977c09ee811e9ea90537695 (diff) | |
download | aur-verbiste.tar.gz |
feat: add script to auto update PKGBUILD
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | update_version.py | 68 |
2 files changed, 69 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..f59ec20aabf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*
\ No newline at end of file diff --git a/update_version.py b/update_version.py new file mode 100755 index 000000000000..12f670e288f3 --- /dev/null +++ b/update_version.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +import re +import subprocess +import urllib.request +from pathlib import Path + +URL_ALL_FILES_SHA512 = "http://perso.b2b2c.ca/~sarrazip/dev/sha512sums.txt" + + +def file_replace(filename, patternToReplace, replacementString): + with open(filename, 'r+', encoding='utf-8') as f: + file_content = f.read() + new_content = re.sub(patternToReplace,replacementString,file_content) + f.seek(0) + f.truncate(0) + f.write(new_content) + + +print(f"Load {URL_ALL_FILES_SHA512} content") +response = urllib.request.urlopen(URL_ALL_FILES_SHA512) +content = response.read().decode('utf-8') + +print("Find last verbiste version and SHA512") +last_version = None +last_sha = None +for line in content.splitlines(): + try: + sha, package = filter(None, line.split(" ")) + except ValueError: + continue + match = re.match("^(?P<pkg>.*?)-(?P<ver>(\d+\.)+\d+)(-\d)?(?P<ext>.*)$", package) + if not match or match.group('pkg') != 'verbiste': + continue + if not last_version or last_version < match.group('ver'): + last_version = match.group('ver') + last_sha = sha + +print(f" -> Version: {last_version}") +print(f" -> SHA512: {last_sha}") + +if not last_version or not last_sha: + print("Missing version or SHA") + exit(1) + + +print("Get current version") +try: + current_version = re.search(r"pkgver=(.*)", Path('PKGBUILD').read_text()).group(1) +except (AttributeError, IndexError): + current_version = "0" +print(f" -> Version: {current_version}") + +if last_version <= current_version: + print("No new version, stop here") + exit(0) + +print("Update PKGBUILD with new version and SHA") +file_replace('PKGBUILD', r"pkgver=.*", f"pkgver={last_version}") +file_replace('PKGBUILD', r"sha512sums=.*", f"sha512sums=('{last_sha}')") + +print("Build .SRCINFO") +Path(".SRCINFO").write_bytes(subprocess.run(["makepkg", "--printsrcinfo"], capture_output=True).stdout) + +print("Git commit") +subprocess.run(["git", "add", "PKGBUILD", ".SRCINFO"]) +subprocess.run(["git", "commit", "-m", f"\"Update to {last_version}\""]) + + |