Deploying an ox-hugo blog with GitHub Actions

The blogging flow provided by ox-hugo suggests that Markdown files should be committed to the source repository along with the Org file. I’m reluctant to do that because the Markdown files are effectively a build artefact in this flow. I also couldn’t find any information on how to integrate ox-hugo’s export functionality with a continuous integration service.

Fortunately, it’s quite simple to do with GitHub Actions. After following the instructions for the hugo-setup Action (these at the time of writing), we must then export the Org file as part of the workflow. set-up-emacs will install emacs and Org. ox-hugo must be cloned separately. Add a step to the job:

- name: Clone Org-mode exporter
  run: git clone https://github.com/kaushalmodi/ox-hugo.git ox-hugo

Then add another step to call the export function:

- name: Export Org file to Markdown
  run: emacs ./posts.org --batch -L ./ox-hugo -l ox-hugo.el --eval='(org-hugo-export-wim-to-md t)' --kill

As written, we are assuming the Org file containing the posts is posts.org and located in the root of the repository. All applicable subtrees are exported but the first argument to org-hugo-export-wim-to-md dictates that behaviour and can be changed.

That’s it! You can view my workflow file to see how it looked just after this change was made.