Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Last active May 11, 2022 19:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ansemjo/fbffb97ac95bfacac904785d36fc81a8 to your computer and use it in GitHub Desktop.
Save ansemjo/fbffb97ac95bfacac904785d36fc81a8 to your computer and use it in GitHub Desktop.
Git hooks for AUR package repositories to test your PKGBUILD before pushing.

AUR package hooks

These hooks are meant to be used in Git repositories that track PKGBUILD files for the Arch User Repository. Place them in .git/hooks/pre-{commit|push} and make sure they're executable.

pre-commit

This hook simply updates the .SRCINFO before every commit by running:

makepkg --printsrcinfo > .SRCINFO

Disable by setting aur.hooks.srcinfo to a falsy value:

git config --local aur.hooks.srcinfo no

pre-push

This hook uses antergos/makepkg to test building the package in a clean environment within a container. It tries to use podman or docker.

WARNING: the Antergos project has been ended in May 2019 and the Docker image used in the script is over 2 years old now.

It clones the repository and checks out every commit that is pushed and different on the remote. Usually that should only be a single ref for AUR packages.

Disable by setting aur.hooks.makepkg to a falsy value:

git config --local aur.hooks.makepkg no

Install

To quickly apply these hooks to your repository run:

for file in pre-commit pre-push; do
  curl -sL https://gist.github.com/ansemjo/fbffb97ac95bfacac904785d36fc81a8/raw/$file > .git/hooks/$file
  chmod +x .git/hooks/$file
done
#!/bin/sh
set -e
# update SRCINFO before committing
if [ "$(git config --bool aur.hook.srcinfo)" != "false" ]; then
echo "aur.hook.srcinfo: updating .SRCINFO ..."
makepkg --printsrcinfo > .SRCINFO
git add .SRCINFO
fi
#!/bin/sh
set -e
# test local refs before pushing to aur
if [ "$(git config --bool aur.hook.makepkg)" != "false" ]; then
echo "aur.hook.makepkg: testing makepkg before pushing ..."
runtime=$(which podman || which docker)
# for every pushed ref that is different
while read locref lochash remref remhash; do
if [ "$lochash" == "$remhash" ]; then continue; fi
echo "aur.hook.makepkg: testing $lochash ..."
"$runtime" run --rm -t \
-v "$PWD:/pkg:ro" -w /tmp \
-u antbs antergos/makepkg \
bash -c "git clone /pkg . && git checkout $lochash && yes | makepkg -sfi"
done
fi
@shackra
Copy link

shackra commented Jan 24, 2021

aur.hook.makepkg: testing makepkg before pushing ...
which: no podman in (/usr/lib/git-core:/home/jorge/.emacs.d/bin/:/home/jorge/.zplug/bin:/home/jorge/.emacs.d/bin/:/home/jorge/.cargo/bin:/home/jorge/.cask/bin:/home/jorge/.gem/ruby/2.4.0/bin:/home/jorge/.gem/ruby/2.7.0/bin:/home/jorge/.emacs.d/bin:/home/jorge/.local/bin:/home/jorge/opt/prey-node-client/bin:/home/jorge/.deno/bin:/home/jorge/.node_modules/bin:/home/jorge/go/bin:/home/jorge/go:/usr/local/bin:/usr/local/sbin:/usr/bin:/opt/cuda/bin:/opt/cuda/integration/nsight-compute:/opt/cuda/integration/nsight-systems:/opt/flutter/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
aur.hook.makepkg: testing 3f286b8a6bf9a89813a2e3644e0243c22eab0dc6 ...
the input device is not a TTY

removing -it fixed it for me.

@shackra
Copy link

shackra commented Jan 24, 2021

Also: found out that if a dependency exists on AUR, the pre-push hook will fail as the dependency cannot be found with pacman.

@ansemjo
Copy link
Author

ansemjo commented Jan 24, 2021

Warning: you shouldn't use the hook in its current form anyway, the Antergos project has been ended and the Docker image used herein is over 2 years old! 😬
You could use whynothugo/makepkg as a substitute if you trust it.

@ansemjo
Copy link
Author

ansemjo commented Jan 24, 2021

Other than that, a custom Docker image based on the official archlinux image with yay installed to first resolve all dependencies via yay -S --asdeps <dependencies> (link) might be a good idea .. An official Arch image was simply not available when I wrote these scripts yet.

@shackra
Copy link

shackra commented Jan 25, 2021

thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment