Setting up a Travis build

The one downside of using Pelican to build the site, as opposed to the Tumblr blog I was previously using, is that I have to actually build the site. This means that I need to have software installed to write a new article which, while not really a huge problem, is slightly awkward. However, I'd read a few things about using online automated build/continuous integration services to build the site for me when I push to the source repo. This means I can write a new article on GitHub [Ed: it was right around this point that I thought "oh yeah, I can write this on GitHub!", and did so], and can therefore write from pretty much anywhere.

So, I read a couple of posts about it, specifically:

I particularly liked this approach as some of the other posts I read use ghp-import and it seemed unnecessary to add a new dependency to the project when git provides the tools for pretty much everything that I want. Initially I implemented it more-or-less as-is, using rsync to copy the changes from the output folder to a fresh checkout of the deployment repo.

Once I had that working, I had a bit of a rethink. I figured that there might be something cleverer that I could do based on the structure I'm using; because the output folder is a submodule, it is already linked to the correct repo for publishing. The first problem I had is that, as I'm not now separately checking out the site repo, I'm relying on Travis's checkout. That isn't authenticated for pushing, and a bit of research suggested that it isn't possible to modify the clone process, but you can add the correct origin back manually. Based on this (criminally underrated) SO post, I added the following to

git remote rm origin
git remote add origin https://${GH_PAGES}$TARGET_REPO

This caused my second problem, that I was now pushing to a detached HEAD, so the changes weren't actually ending up in the master branch. To fix this took another SO question, which suggested committing to a temporary branch, committing the changes then switching that back into master before the push, so I added:

git checkout -b temp
git checkout -B master temp

And that did it! I'm planning to set this all up as a neat Pelican starter project that anyone can easily fork, so keep an eye out for that if you're interested in setting up your own Pelican site with minimal fuss.

Comments !