This GitHub action will build your Hugo site, and then publish back to GitHub Pages.
TOKEN
: A GitHub access token that can push to other repos, which in this case will be your GitHub pages repo. We cannot useGITHUB_TOKEN
as defined here because it is a locally scoped token to a specific repo.
GITHUB_ACTOR
: The name of the person or app that initiated the workflow. For example, octocat. See here.TARGET_REPO
: This is the repo slug for the GitHub pages site. e.g.benmatselby/benmatselby.github.io
.TARGET_BRANCH
: This is the branch to push the public files e.g.docs
. Default ismaster
branch.HUGO_VERSION
: This allows you to control which version of Hugo you want to use. There is a default within the action, but this may be out of date.HUGO_EXTENDED
: If set totrue
, the extended version of Hugo will be used. Default isfalse
.HUGO_ARGS
: Arguments passed tohugo
.CNAME
: Contents of aCNAME
file.
name: Push to GitHub Pages on push to master
on:
push:
branches:
- master
jobs:
build:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v1
- name: Deploy the site
uses: benmatselby/hugo-deploy-gh-pages@master
env:
HUGO_VERSION: 0.80.0
TARGET_REPO: benmatselby/benmatselby.github.io
TARGET_BRANCH: master
TOKEN: ${{ secrets.TOKEN }}
HUGO_ARGS: '-t academic'
CNAME: benmatselby.github.io
This will:
- Clone the
TARGET_REPO
into thebuild
folder. - Commit the changes with the
date
as the git commit message. - Push back to GitHub using the
TARGET_BRANCH
environment variable.
To test this action locally, you can run the following in your hugo site:
Build the docker image
docker build --pull --rm -f "Dockerfile" -t hugodeployghpages:latest .
Run the standard version of Hugo and the action.
# cd to your hugo site
docker run --rm \
-eGITHUB_TOKEN \
-eTARGET_REPO=benmatselby/benmatselby.github.io \
-v "$(pwd)":/site/ \
--workdir /site \
hugodeployghpages
Run the extended version of Hugo, and the action.
# cd to your hugo site
docker run --rm \
-eHUGO_EXTENDED=true \
-eGITHUB_TOKEN \
-eTARGET_REPO=benmatselby/benmatselby.github.io \
-v "$(pwd)":/site/ \
--workdir /site \
hugodeployghpages
For an in depth tutorial, see this blog post. It is geared mostly at users of the Hugo Academic theme, but should be more broadly applicable.