So after I moved my website from wordpress to hugo I was curious if I could streamline deploying new posts via some sort of CI. Since this website is hosted on Github Pages and therefore has a Github repo in the background I was curious if Githubs' “Actions” stuff, which is their CI environment, would do the job. After some digging through forum entries I had a working version of a publish action, which builds and deploys my website automatically.

Basically every time I push a new commit to the main branch the action compiles and deploys the hugo project to the branch that is hosted on Pages

First I had to create a secret access token for the deploy action. Without it the action would not have permission to push to my repository. Thats done via Repo -> Settings -> Secrets.

After that I needed a folder .github directory on my main branch, in which I created a main.yml file. This file contains the action itself.

Here’s the yml file for the Action:

name: publish

on:
  push:
    branches:
      - main # Set a branch to deploy

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true # Needed for the hugo theme, since it's a git submodule
          fetch-depth: 0

      - name: Hugo setup
        # A action to build hugo projects from user peaceiris. Works like a charm!
        uses: peaceiris/actions-hugo@v2.4.13
        with:
          # The Hugo version to download (if necessary) and use.
          hugo-version: 0.79.0
          # I need hugo-extended for the theme to function properly
          extended: true

      - name: Build
        # Change working directory to the hugo project directory
        working-directory: ./tehmightypotato
        run: hugo --minify

      - name: Deploy
        # The actual deploy action from user JamesIves. Had great support from him working this out!
        uses: JamesIves/github-pages-deploy-action@3.7.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This is the reference to the secret I created. It's basically an access token to this Repo.
          BRANCH: gh-pages # The branch the action should deploy to.
          FOLDER: tehmightypotato/public # The folder the action should deploy.
          CLEAN: true # Automatically remove deleted files from the deploy branch

I then created a branch called gh-pages, which I linked to the Github Pages process. I deleted all the files from that one, since this is the branch that’s getting deployed.

Notice how the main branch contains my normal repository with the hugo project and the gh-pages branch contains only the built hugo files. Main Branch Pages Branch

And that’s my first contact with CI! As a long-time Factorio and Modded Minecraft player this satisfies my need for automation to an extent. Still, I want more! Maybe next time I’ll try setting up a Unity Build Pipeline 🕹ī¸