Permanent link to this article HOWTO: Submit a package to AUR | Travis' Blog, welcome to check it out.
Recently, I discovered gptcommit, a small tool written in Rust that uses gpt to generate commit messages. The basic idea is to pass the output of git diff
to gpt, allowing it to generate text that can be used as commit messages. It's perfect for lazy people like me. Humans are really lazy to the point of taking off😂
There is a package called gptcommit-git on the Arch User Repository (AUR), but the version is stuck at 0.1.16. I think there might be some issues with the PKGBUILD
file, which requires manual updates frequently. Since there is no gptcommit-bin
in AUR either, and for the convenience of future one-click updates with yay -Syu
, I'm planning to create and upload my own package. It's also a small contribution to the community ☺.
First, I'll search the most authoritative Arch Wiki to see how to properly write a package and upload it. I'll also refer to the Arch Packaging Guidelines1 and Arch Submission Guidelines2, and ask ChatGPT for some advice.
The author of gptcommit provides pre-compiled binary files for various platforms in the release section. We just need to download and extract them to the /usr/bin
directory. It's a simple packaging process. Here's the PKGBUILD
file I wrote. After writing it, I can generate a tarball in the current directory by using the makepkg -Acs
command, and then install it with sudo pacman -U <tarball>pkg.tar.zst
.
# Maintainer: travismtg <[email protected]>
pkgname=gptcommit-bin
pkgver=0.5.8
pkgrel=1
pkgdesc="A git prepare-commit-msg hook for authoring commit messages with GPT-3."
arch=('any')
url='https://github.com/zurawiki/gptcommit'
license=('MIT')
depends=()
conflicts=('gptcommit-git' 'gptcommit')
source=('https://github.com/zurawiki/gptcommit/releases/download/v0.5.8/gptcommit-x86_64-unknown-linux-gnu.tar.gz')
sha256sums=('d0efe345dd4b598a8c06bd9ba7036ae4e148141deb606c64e612e8959273cedc')
package() {
cd "$srcdir"
mkdir -p "$pkgdir/usr/bin/"
tar zxvf gptcommit-x86_64-unknown-linux-gnu.tar.gz -C "$pkgdir/usr/bin/"
}
After verifying that the installation is successful, I can prepare for the upload.
- First, I'll register an AUR account and set up my SSH public key to prove my identity.
- Then, I can create a new repository by cloning it directly using
git clone ssh://[email protected]/gptcommit-bin.git
(Yes, cloning directly creates a repository). - Next, I'll put the
PKGBUILD
file I just wrote into the repository and usemakepkg --printsrcinfo > .SRCINFO
to generate the package's basic information file. git add PKGBUILD .SRCINFO && git commit -m "v0.5.8"
git push --set-upstream origin master
to push to the remote repository.
Now I can see that the package I published, gptcommit-bin, is visible on the website. But since I'm already doing this, I might as well automate it a bit more and let it update itself whenever there's a new version. It's quite tiring to manually modify the version number, download URL, and sha256 information every time there's a new version.
#!/usr/bin/env bash
# Created by travismtg
# Thu Apr 27 11:08:31 PM CST 2023
# usage: ./update.sh /path/to/pkg
DES=$1 # directory that contains the PKGBUILD file
cd $DES
VERSION_URL=`curl -s https://api.github.com/repos/zurawiki/gptcommit/releases/latest |\
jq -r '.tag_name as $version | .assets[] | select(.name | contains("linux-gnu")) | $version + " " + .browser_download_url'`
VERSION=$(echo $VERSION_URL | cut -d' ' -f1 | sed 's/v//')
CURRENT_VERSION=$(grep 'pkgver=' PKGBUILD | sed 's/pkgver=//')
echo latest version is $VERSION
echo current version is $CURRENT_VERSION
if [[ $VERSION == $CURRENT_VERSION ]]; then
echo exit
exit
fi
URL=`echo $VERSION_URL | cut -d' ' -f2`
POSTURL=$(echo $URL | sed 's/\//\\\//g')
TARGET=$(echo $URL | grep -o 'gptcommit-x86.*tar.gz')
wget $URL -O $TARGET
SUM=$(sha256sum $TARGET | cut -f1 -d' ')
sed -i 's/^source=(.*)/source=('"'"$POSTURL"'"')/' PKGBUILD
sed -i 's/^sha256sums=(.*)/sha256sums=('"'"$SUM"'"')/' PKGBUILD
sed -i 's/^pkgver=.*/pkgver='$VERSION'/' PKGBUILD
makepkg --printsrcinfo > .SRCINFO
# commit and push
git add PKGBUILD .SRCINFO
git commit -m "$VERSION"
git push
Now I only need to run ./update.sh /path/to/pkg
to update the package files. I'll put these files on the server and set up a crontab
to check for version updates every day at 10 AM. This way, the gptcommit package will be automatically updated.
That's the end of this article. My biggest takeaway from this process is that ChatGPT is really useful. I just need to ask it how to get the latest release of a GitHub repository and filter out the download link for Linux, and it quickly finds the GitHub API and writes the jq
rules for me. Of course, I could have figured out these things by myself by reading the documentation or Googling, but ChatGPT compresses the time it takes to acquire knowledge and can personalize the information I want. This tireless teacher is amazing.