Deploy Hugo Site Using GitHub Actions
After creating a new project using Hugo’s Quick Start guide, you can then deploy to GitHub Pages.
Git Branches
For this site, we are deploying the project hosted at napjoseph/napjoseph.github.io.
Since this is an Organization Pages-type repository, we will be using following branches for our workflow:
$ git branch
master # the branch that GitHub pages will serve the files from
stable # the main development branch where all pull requests will be merged to
id_your_feature # additional development branches for new features
Add your Deploy Key
Follow the tutorial over at peaceiris/actions-gh-pages and add an SSH deploy key for your project.
Create your GitHub Action
Afterwards, create a directory for your workflows and add the config file for your new action.
$ mkdir -p .github/workflows
$ touch .github/workflows/deploy.yml
# file: .github/workflows/deploy.yml
name: deploy-to-master
on:
push:
branches:
- stable
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
persist-credentials: false
- name: Update theme
run: git submodule update --init --recursive
- name: Setup Hugo
uses: peaceiris/[email protected]
with:
hugo-version: '0.74.3'
- name: Build
run: HUGO_ENV=production hugo --minify
- name: Deploy
uses: peaceiris/[email protected]
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./public
publish_branch: master
keep_files: false
allow_empty_commit: true
Deployment
After merging your pull requests to the stable
branch, it should automatically
deploy to the master
branch.