Nap Joseph Calub

Software Engineer and Open Source Enthusiast

Deploy Hugo Site Using GitHub Actions

Published on June 27, 2020

Hugo

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

.github/workflows/deploy.yml

1name: deploy-to-master
2
3on:
4 push:
5 branches:
6 - stable
7
8jobs:
9 build-and-deploy:
10 runs-on: ubuntu-latest
11 steps:
12 - name: Checkout
13 uses: actions/checkout@v2
14 with:
15 persist-credentials: false
16
17 - name: Update theme
18 run: git submodule update --init --recursive
19
20 - name: Setup Hugo
21 uses: peaceiris/actions-hugo@v2
22 with:
23 hugo-version: '0.74.3'
24
25 - name: Build
26 run: HUGO_ENV=production hugo --minify
27
28 - name: Deploy
29 uses: peaceiris/actions-gh-pages@v3
30 with:
31 deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
32 publish_dir: ./public
33 publish_branch: master
34 keep_files: false
35 allow_empty_commit: true

###Deployment

After merging your pull requests to the stable branch, it should automatically deploy to the master branch.

© 2021 Nap Joseph Calub. All rights reserved.

Light Mode
Dark Mode