You might want to consider the following for grub. Note that it adds no options to grub-install, so you must make sure what is correct for you.
And, I didn’t test this, so it may contain bugs. ![]()
previous_version=$(pacman -Q grub)
yay
current_version=$(pacman -Q grub)
if [ "$previous_version" != "$current_version" ] ; then
grub-install
grub-mkconfig -o /boot/grub/grub.cfg
fi