Github Actions + Hugo Blog

Posted September 3, 2022 by Jacob Sauni ‐ 2 min read

The final piece to setting up this blog was to automate the deployment of new posts. If you haven’t read any of the earlier posts (or gathered from the title), I’d be using Github Actions to configure the deployment pipeline.

First time using Github Actions was when I set up Github Actions for the AWS resources that host this blog. Simplified, surely this would be a copy + paste of the .github/workflows dirctory, search and replace terraform with hugo within the yml file and job done.

Gist of it

To be fair, it pretty much was that. Only difference was I leveraged the peaceiris/actions-hugo@v2 action to install Hugo. I had pretty much the same build steps as well.

  • Checkout code
  • Setup Hugo
  • Build Hugo
  • Deploy Hugo Dry Run (pull request)
  • Comment on pull request (pull request)
  • Deploy Hugo (push on main branch)

I only had one issue when setting this workflow up. During the Deploy Hugo Dry Run step, the output from the command was not being included in its entirety when the Comment on pull request step would post to the pull request. The output was being truncated and only the first line was being included. This was weird as I had no issues when setting this up for my other repo and Terraform.

After reading some posts online, I couldn’t find any reasons why this was happening. But got it working in the end by adding some hack I found to the workflow config to escape some characters so I could capture the multiline command output.

So instead of the step looking like this:

run: hugo deploy --dryRun

It looked like this:

run: |
  hugo_deploy_output=$(hugo deploy --dryRun)
  echo $hugo_deploy_output
  echo "::set-output name=hugo_deploy_output::${hugo_deploy_output}"  

This would capture the output, escape the characters and set the step output variable. This output variable would be used in the Comment on pull request step. Once this was in, I was getting the expected command output written to the pull request as a comment.

What next

That wraps up the blog “series” I think. I’m keen to jump into some docker/kubernetes learning next, so will document what I do there.