💸Save up to $132K/month in CI costs!👉 Try Free
Skip to main content
← Back to workflows

How to Set Up Hugo in GitHub Actions

peaceiris-actions-hugo -
GitHub Action
actions-hugo v3.0.0
1,360
Contributors
Contributor - peaceiris
Categories

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of actions-hugo GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.119.0'

actions-hugo logo

Hugo Actions

GitHub Actions for Hugo ⚡️ Setup Hugo quickly and build your site fast. Hugo extended, Hugo Modules, Linux (Ubuntu), macOS, and Windows are supported.


What is actions-hugo?

Since Hugo is our static site generator, this can really make the deployment work pretty smooth. This action installs Hugo directly in the GitHub Actions-provided virtual machine and supports the extended version, Hugo Modules, and operating systems like Linux (Ubuntu), macOS, and Windows.

How to Set Up Hugo Extended in GitHub Actions

The extended version of Hugo includes support for advanced features that are not available in the standard version. Here's how to set it up:

name: Build and Deploy Hugo Site
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Hugo Extended
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.119.0'
extended: true
- name: Build
run: hugo --minify
- name: Deploy
run: ./deploy.sh

Key Features of Hugo Extended:

  • SCSS/SASS Support: Allows you to write stylesheets with more advanced syntax and functionalities.
  • PostCSS Integration: Enables the use of tools like Autoprefixer within your Hugo project.

Setting Up Caching for Hugo Modules

Caching Hugo Modules in GitHub Actions can drastically decrease build times by reusing the previously downloaded modules instead of fetching them each time. Follow these steps to add caching to your Hugo build process.

name: Build and Deploy Hugo Site
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Hugo Modules
uses: actions/cache@v4
with:
path: /home/runner/.cache/hugo_cache # Adjust based on Hugo version and OS
# path: /tmp/hugo_cache # Uncomment for Hugo versions < v0.116.0
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Build
run: hugo --minify

Key Configuration Options:

  • Path: Specifies the directory to cache. Use the appropriate path for your setup.
  • Key: Defines the cache key, and here it uses the hash of go.sum to detect changes in dependencies.
  • Restore-keys: Provides a list of keys to try when restoring the cache in case of a cache miss.