Deploying to github pages is not as easy as I thought. I tried several things for building a Github Action workflow, however this is only meant for actions related to the repository in question.

In the end, I follow the approach as mentioned on the Hugo website with a local script. I have pimped it by fetching the latest commit message and the use this message for committing the changes in the generated site.

#!/bin/sh

# If a command fails then the deploy stops
set -e

printf "\033[0;32mDeploying updates to GitHub...\033[0m\n"
printf "\033[0;32mGetting last commit message...\033[0m\n"
commsg="$(git log -1 --pretty=%B)"
# Build the project.
printf "\033[0;32mBuilding the site...\033[0m\n"
hugo # if using a theme, replace with `hugo -t <YOURTHEME>`

# Go To Public folder
cd pieterjd.github.io

# Add changes to git.
git add .

# Commit changes.
git commit -m "$commsg"
# Push source and build repos.
git push origin master

References