Created
May 29, 2023 07:02
-
-
Save akarsh1995/aae034c5f4c88734e1e17f3c7e6ea01a to your computer and use it in GitHub Desktop.
pre-push git hook to generate Arch User Repository files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python | |
| import subprocess | |
| import re | |
| from pathlib import Path | |
| import os | |
| WD = Path().absolute() | |
| PKGBUILD_IN_PATH = Path("PKGBUILD").absolute() | |
| OUT_PATH = Path("aur_out").absolute() | |
| OUT_PATH.mkdir(parents=True, exist_ok=True) | |
| PKGBUILD_OUT_PATH = OUT_PATH.joinpath("PKGBUILD").absolute() | |
| SRCINFO_OUT_PATH = OUT_PATH.joinpath('.SRCINFO').absolute() | |
| def main(): | |
| print("Version update for PKGINFO") | |
| makepkg = subprocess.run('printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"', shell=True, check=True, capture_output=True) | |
| version_number = makepkg.stdout | |
| version = version_number.decode('utf-8') | |
| pkgbuild_text = PKGBUILD_IN_PATH.read_text() | |
| sub = re.sub(r"pkgver=.+", f"pkgver={version}", pkgbuild_text) | |
| PKGBUILD_OUT_PATH.write_text(sub) | |
| print("Copying install file") | |
| m = re.search(r"install='(.*?)'", pkgbuild_text) | |
| file_name = m.group(1) | |
| IN_INSTALL_FILE = WD.joinpath(file_name) | |
| OUT_PATH.joinpath(file_name).write_text(IN_INSTALL_FILE.read_text()) | |
| print("Generating .SRCINFO") | |
| os.chdir(OUT_PATH) | |
| srcinfo = subprocess.run(f'makepkg -p {PKGBUILD_OUT_PATH.absolute()} --printsrcinfo', shell=True, check=True, capture_output=True) | |
| SRCINFO_OUT_PATH.write_bytes(srcinfo.stdout) | |
| os.chdir(WD) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment