Automating Sourcehut Builds with Wordpress

Posted on 2024-08-10

I run a few websites in my spare time. I run this one, which is a simple Gemini/barebones HTML site backed by Git, and I run a few Wordpress instances. For these sites, I tend to build my own frontends using a framework like Astro[1] so that I have ultimate flexibility over the design and limited interactivity of my sites. It's a nice workflow: I can build a website without having to mess around too much with PHP/Wordpress theming nonsense and my users can just use Wordpress, with which they're already familiar.

1 - Astro

These sites are currently developed on GitHub rather than Sourcehut for one simple reason: automating the Wordpress setup. I use content collections and the Wordpress API to populate the content of a site, which means I never usually have to touch the code itself unless a design change or dependency update is required. To ensure the site fetches the latest data from Wordpress, I deploy the site using Netlify and make use of build webhooks to trigger a new build when a change is made on the Wordpress side. This is nice and hands-off, but ideally I wanted to use Sourcehut and Sourcehut Builds to manage this.

Given that Sourcehut Builds doesn't (yet) support build webhooks, I've not really looked at it too deeply. However, it does have a GraphQL API that enables you to request builds, so I figured the best thing to do would be to build a plugin that allows you to send a build request when a page/post is created/updated/deleted. This mimics the behavior of the webhook-based approach I currently have going.

So that's exactly what I've done. I created a Wordpress builds plugin[2] that anyone can freely use to hook up a Wordpress site to Sourcehut Builds to automate rebuilding a frontend or running some other build process in response to updates. It may only be useful to me, but that's okay too.

2 - The plugin code project on Sourcehut

✉️ Tell me what you think