Hugo deploy with GitHub Actions
The past couple of posts have dealt with using Apple Shortcuts to stage a Hugo blog post. Today, let’s use GitHub Actions to deploy our changes and update our site.
There are several actions out there that accomplish this goal; however, I landed on this particular one.
The deploy-hugo-to-s3-action from Albert Moreno provided the cleanest—driest—workflow in my opinion.
In order for this to work, you must add the deployment steps to your config.toml
and ensure this is checked in to your repo.
Now, using his action as the basis, this is the final workflow for my blog deployment:
name: Deploy Hugo site to S3 bucket
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v2
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Deploy site
uses: plopcas/hugo-s3-action@v1.3.0
env:
AWS_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
MINIFY: 'true'
So simple.
A push to the main
branch—be that a direct push or a PR into—fires off the action.
We then call the checkout
action to pull our code from our repo, then we simply call his action to finalize.
Using GitHub secrets, we can store our AWS credentials to ensure these are not written to any file or transferred in plaintext.
The result is a published blog to S3. And the kicker is, if you’re leveraging CloudFront, all you need to do is include the Distribution ID to fire off an invalidation.
Super slick!
That’s it. A “Mac-agnostic” workflow that can fire up a staged blog post on any Apple device that you can then check into GitHub and deploy to an S3 bucket that hosts your blog.
For those that want to tinker, here’s my latest version of the Blog Post Apple Shortcut.