Software Engineer using Go and TypeScript

Deploy Hugo Site Using GitHub Actions

Published on June 27, 2020

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

Deployment

After merging your pull requests to the

stable
branch, it should automatically deploy to the
master
branch.