In this post, I’ll walk you through a complete GitHub Actions workflow for building and deploying a Hugo static website to GitHub Pages. This setup is ideal for developers who want a free, automated hosting solution for their open source projects, blogs, documentation sites, or portfolios. It replaces manual uploads with a push to deploy pipeline.
The workflow triggers on pushes to the main branch (or manually via the Actions tab), builds your Hugo site using Node.js for any custom scripts, and deploys the output to GitHub Pages. It’s efficient, secure, and leverages official GitHub Actions for reliability.
Prerequisites
- A Hugo website in a GitHub repository
- GitHub Pages enabled for the repository (go to Settings > Pages and then select “GitHub Actions” as the source)
Example of a setup for some software I released as open source.

Setting Up the Workflow
Create a new file in your repository at .github/workflows/deploy.yml.
Here’s the YAML configuration for the workflow:
name: Deploy Hugo Website to GitHub Pages
on:
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 'latest'
cache: 'npm' # Optional: Cache npm deps for faster runs
- name: Install NPM packages
run: npm ci # Use 'ci' for cleaner installs in CI
- name: Build Hugo site
run: npm run build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
This workflow triggers on pushes to the main branch. It sets up Hugo and Node.js, installs dependencies, builds the site. If the build is successful then then deploy job will run and deploy the built Hugo website to GitHub Pages.
Additional Steps
- Ensure your repository has GitHub Pages enabled.
- If using a custom domain, add a
CNAMErecord for your domain as per the GitHub Pages instructions. - The workflow assumes your build command is
npm run buildand outputs to./public. Adjust if necessary.
Conclusion
Automating your Hugo website deployment with GitHub Actions and GitHub Pages streamlines your workflow, ensuring fast and reliable updates. By leveraging GitHub’s built in CI/CD capabilities, you can focus on content creation while the deployment happens automatically. This setup not only saves time but also provides peace of mind with version controlled, reproducible deployments.
Latest Blog Posts:
How to do backups with rsync on Linux
Comprehensive guide to using rsync for backups on Linux systems
How to use GitHub Actions Workflow to Deploy Your Website using rsync automatically
Learn how to automate your Hugo website deployment with GitHub Actions and rsync for fast, secure updates.
How to add Lunr.js Search to Your Hugo Website
Learn how to integrate Lunr.js for fast, client-side search functionality in your Hugo static site.
How to use Github Actions to Deploy a Hugo Website to GitHub Pages automatically
In this post, I'll walk you through a complete GitHub Actions workflow for building and deploying a Hugo static website to GitHub Pages. This setup is ideal for developers who want a free, automated hosting solution for their blogs, documentation sites, or portfolios. It replaces manual uploads with a push-to-deploy pipeline.
How to Setup Hugo Admonitions (Markdown Callouts in Hugo)
By adding Hugo Admonitions to your website so you can easily add stylish note bars for things like tips, warnings, cautions, important information etc. You can do this quickly and easily directly using markdown.
How to setup Syntax Highlighting with Copy Button using Hugo
In this post, I’ll show you how to add syntax highlighting and a ‘Copy’ button to your Hugo code blocks using a single self-contained JavaScript file. You’ll be able to highlight code in multiple languages, optionally show line numbers, and let users copy snippets with one click.
How to strip unused CSS from your CSS files and Minify them into a single CSS file using Hugo
Using Hugo with PostCSS and PurgeCSS allows you to automatically remove unused CSS and bundle all your styles into a single minified file for production, improving page load times and performance.
Make an application always load as a floating window in Cosmic Desktop
Make an application always load as a floating window in Cosmic Desktop
Why I migrated from Wordpress to Hugo
My reasons for migrating from Wordpress to the Hugo static website generator
Using Gtk4 With C# and Gir.Core Box Layout Tutorial
In this box layout tutorial, you will learn how to build a C# Gtk Application that makes use of the box layout to display multiple widgets both vertically and horizontally. You will also learn how to use a box layout to display an icon and a label inside a Gtk.Button widget.