Hugo blog - Deployment automation with Github
Automating Hugo blog deployment using Github Actions!
Why?
I am currently porting over from an old VPS on Linode running Centos 6 and a smattering of old stuff. It was previously running a Wordpress install. It’s working fine, but I feel like running a DB + WebServer + PHP for a simple blog is way too overkill.
The idea was to move to a static framework where I could host the actual content the easiest way possible. I’ve picked Hugo just based of my liking of the product and the abundance of free themes.
Here is the final setup :
- Hugo 0.59.0
- GitHub Pages
- Auto-deployment with Github Actions when content is pushed into the repository.
- Binario theme with syntax highlight
Github workflow
name: hugo-build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build the hugo static files.
run: |
sudo docker run --rm -v $(pwd):/src laurentfdumont/laurent-hugo hugo
- name: Commit new files.
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Automatic GitHub Actions commit" -a
- name: Push changes.
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Breaking it down
- Runs on Ubuntu latest as a runner.
- We first use
actions/checkout@v1
to checkout the latest commit - We then build the static files into the
docs
folder. - We then commit + push the new files into the repository (this doesn’t trigger an automatic rebuild). It uses a built-in token.
- Note that this only works with private repository due to an ongoing bug with
GITHUB_TOKEN
and public repositories. See the following issue : https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/m-p/26869/highlight/true#M301