Auto-build APK when upstream APKBUILD changes

By chimo on (updated on )

TL;DR

I have a custom APKBUILD (hugo-nodeploy) and I want to automatically re-build it when the upstream APKBUILD (hugo) changes. Skip to the Detect APKBUILD version mismatch section if you don’t care about the context.

Ramblings

I recently noticed something new in `hugo build` output:

Start building sites …
hugo v0.152.2+extended+withdeploy

I’m referring to the “+withdeploy” part. I never noticed that before, got curious, and looked it up.

The change in the “hugo” Alpine Linux package happened on June 12th. It probably appeared on my end when I upgraded to Alpine 3.23. The Alpine commit message refers to hugo release v0.137.0 and PR #12995 in the upstream repo, which mentions issue #12994 for context.

In short, the new release without the “deploy” feature:

[…] shaves off about 40% of the binary size.

and, in some contexts, gets rid of:

[…] questionable network activity from Hugo

The network activity, although a little strange, doesn’t concern me too much (I’m assuming it’s benign). I also don’t really know if my setup is affected. The `hugo` binary isn’t very big to being with, so the size reduction isn’t super significant in my scenario.

So why am I writing about this if it doesn’t really matter to me? Well, I don’t use the `deploy` feature so getting rid of it has no downsides and a couple of small benefits. More importantly though, it got me to thinking: “how would I approach this if I absolutely needed to get rid of this feature?”

One obvious solution is to get the precompiled binary, but where’s the fun in that? Another solution is to build my own package, which I did. But “with custom packages comes some responsibilities”. I want to follow the `hugo` Alpine package releases as closely as possible (recompile due to Go version changes, security fixes, etc.) but just without the “withdeploy” feature. What’s the easiest way to do that?

What I came up with probably isn’t the easiest way, but I think that it’s something that’ll work for my needs, and might re-usable for other packages in the future, if need be. Basically, I want to do two distinct things:

  1. Detect when my APKBUILD’s version doesn’t match upstream’s APKBUILD version.
  2. Build my custom package the same way as upstream, but without “withdeploy”.

Detect APKBUILD Version Mismatch

This part relies on the fact that my custom package is deployed to my custom APK repository and accessible from the current machine (i.e.: I can do `apk search -e hugo-nodeploy`).

A heavy requirement, perhaps, but then it should make it easy to achieve our first goal: get the versions of both “hugo” and “hugo-nodeploy” via `apk search`, compare the two (in my case, with `apk version`) and see if they differ.

Build Package

If the versions don’t match, we need to build our package:

  1. Get the upstream files.
    Right now, I’m using `wget` to leverage GitLab’s feature that lets us download a specific directory from a repository.
  2. Patch upstream’s APKBUILD with our changes.
  3. Run `abuild checksum && abuild -r`

Running the Script

I simply dropped `check-hugo.sh` in `/etc/periodic/daily/`. We’ll see how it goes.