Maintaining AUR packages with Renovate
Mar 16, 2023 · 5 minute readOne big advantage that Arch Linux has over other distributions, apart from being able to say “BTW I use Arch.”, is the Arch User Repository (AUR). It’s a community-driven repository with over 80,000 packages. If you’re looking for a package, chances are you’ll find it in the AUR.
Keeping all those packages up to date, takes a lot of manual effort by a lot of volunteers. People have created and used tools, likeurlwatchandaurpublish, to let them know when upstream releases are cut and automate some parts of the process. I know I do. But I wanted to automate the entire process. I thinkRenovatecan help here.
Updating versions with Renovate
Renovate is an automated dependency update tool. You might have seen it opening pull requests on GitHub and making updates for npm or other package managers, but it’s a lot more powerful than just that.
Renovate has a couple of concepts that I need to explain first:datasourcesandmanagers. Datasources define where to look for new versions of a dependency. Renovate comes with over 50 different datasources, but the one that is important for AUR packages is thegit-tagsdatasource. Managers are the Renovate concept for package managers. There isn’t an AUR orPKGBUILDmanager, but there is aregex managerthat I can use.
I can create arenovate.jsonconfiguration with the following regex manager configuration:
1{2"regexManagers":[3{4"fileMatch":["(^|/)PKGBUILD$"],5"matchStrings":[6"pkgver=(?<currentValue>.*) # renovate: datasource=(?<datasource>.*) depName=(?<depName>.*)"7],8"extractVersionTemplate":"^v?(?<version>.*)$"9}10]11}Breaking that down:
- The
fileMatchsetting tells Renovate to look for anyPKGBUILDfiles in a repository - The
matchStringsis the regex format to extract the version, datasource, and dependency name from thePKGBUILD - The
extractVersionTemplateis to handle a “v” in front of any version number that is sometimes added to Git tags
And here’s an extract from the PKGBUILD for thebicep-binAUR package that I maintain:
1pkgver=0.15.31# renovate: datasource=github-tags depName=Azure/bicepHere I’m configuring Renovate to use thegithub-tagsdatasource and to look in theAzure/bicepGitHub repositoryfor new versions. That means it’ll look in thelist of tags for theAzure/biceprepositoryfor any new versions. If Renovate finds any new versions, it’ll automatically update thePKGBUILDand open a pull request with the updated version.
So I’ve automated thePKGBUILDupdate, but that’s only half of the work. The checksums and.SRCINFOmust be updated before pushing to the AUR. Unfortunately, Renovate can’t do that (yet, seeRenovate issue #16923), but GitHub Actions can!
Updating checksums and.SRCINFOwith GitHub Actions
Updating the checksums withupdpkgsumsis easy, and generating an updated.SRCINFOwithmakepkg --printsrcinfo > .SRCINFOis straightforward too. But doing that for a whole repository of AUR packages is going to be a little trickier. So let me build up the GitHub actions workflow step-by-step.
First, I only want to run this workflow on pull requests targeting themainbranch.
1on:2pull_request:3types:4- opened5- synchronize6branches:7- mainNext, I’m going to need to check out the entire history of the repository, so I can compare the files changed in the latest commit with the Git history.
1jobs:2updpkgsums:3runs-on:ubuntu-latest4steps:5-name:Checkout6uses:actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c# v3.3.07with:8fetch-depth:09ref:${{ github.ref }}Getting the package that changed in a pull request requires a little bit of shell magic.
1-name:Find updated package2run:|3#!/usr/bin/env bash4set -euxo pipefail56echo "pkgbuild=$(git diff --name-only origin/main origin/${GITHUB_HEAD_REF} "*PKGBUILD" | head -1 | xargs dirname)" >> $GITHUB_ENVNow I’ve found the package that changed in the Renovate pull request, I can update the files.
This step in the workflow uses a private GitHub Action that I have in myaur-packagesrepository. I’m not going to break it down here, but at its core it runsupdpkgsumsandmakepkg --printsrcinfo > .SRCINFOwith a little extra configuration required to run Arch Linux on GitHub Actions runners. You cancheck out the full code on GitHub.
1-name:Validate package2if:${{ env.pkgbuild != '' }}3uses:./.github/actions/aur4with:5action:'updpkgsums'6pkgname:${{ env.pkgbuild }}Finally, once thePKGBUILDand.SRCINFOare updated I need to commit that change back to the pull request.
1-name:Commit2if:${{ env.pkgbuild != '' }}3uses:stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a# v4.16.04with:5file_pattern:'*/PKGBUILD */.SRCINFO'Check outthis pull request forbicep-binwhere Renovate opened a pull request, and my GitHub Actions workflow updated theb2sumsin thePKGBUILDand updated the.SRCINFO.
But why stop there? Let’s talk about publishing.
Publishing to the AUR
Each AUR package is its own Git repository. So to update a package in the AUR, I only need to push a new commit with the updatedPKGBUILDand.SRCINFO. Thankfully,KSXGitHubcreated thegithub-actions-deploy-aurGitHub Actionto streamline the whole process.
If I create a new GitHub Actions workflow to publish to the AUR, I can reuse the first two steps from my previous workflow to check out the repository and find the updated package. Then all I need to do is to use thegithub-actions-deploy-aurGitHub Action:
1-name:Publish package2uses:KSXGitHub/github-actions-deploy-aur@065b6056b25bdd43830d5a3f01899d0ff7169819# v2.6.03if:${{ env.pkgbuild != '' }}4with:5pkgname:${{ env.pkgbuild }}6pkgbuild:${{ env.pkgbuild }}/PKGBUILD7commit_username:${{ secrets.AUR_USERNAME }}8commit_email:${{ secrets.AUR_EMAIL }}9ssh_private_key:${{ secrets.AUR_SSH_PRIVATE_KEY }}All together now
If you own any AUR packages and want to automate some of the maintenance burden, check outmy AUR packages template GitHub repository. It contains all of the steps I showed in this blog post. And if you want to see how it works in practice, check outmy AUR packages GitHub repository.