actions/hugo-build/action.yml
Den Delimarsky 2451a73720
Add hugo-build composite action
Installs Go + Hugo extended and builds a Hugo site in preview
(--buildDrafts --buildFuture, development env) or production mode.

Extracted from the MCP repo's blog-preview, deploy-blog, and stage-blog
workflows where the ~12-line Go+Hugo install+build block was duplicated.
Placing it here (rather than as a local .github/actions/ composite in the
MCP repo) means stage-blog.yml can reference it at @main — fork-proof by
construction, no two-checkout dance needed when building fork-submitted
content.
2026-03-11 20:36:43 +00:00

70 lines
2.1 KiB
YAML

name: Hugo Build
description: >-
Installs Go + Hugo (extended) and builds a Hugo site. Set mode=preview to
include drafts and future-dated posts (development env); mode=production
for release builds.
inputs:
working-directory:
description: Directory containing the Hugo site (with hugo.toml)
required: false
default: '.'
mode:
description: >-
'preview' (HUGO_ENVIRONMENT=development, --buildDrafts --buildFuture) or
'production' (HUGO_ENVIRONMENT=production, no drafts/future)
required: false
default: preview
base-url:
description: >-
Hugo --baseURL. Typically '/' for CF Pages previews (root-relative
paths); pass the canonical URL for production.
required: false
default: '/'
hugo-version:
description: Hugo extended version to install
required: false
default: '0.148.0'
go-version:
description: Go version for Hugo modules
required: false
default: '1.24'
outputs:
public-dir:
description: Path to the built static site (working-directory + /public)
value: ${{ inputs.working-directory }}/public
runs:
using: composite
steps:
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: ${{ inputs.go-version }}
- name: Install Hugo
shell: bash
env:
HUGO_VERSION: ${{ inputs.hugo-version }}
run: |
wget -O "${RUNNER_TEMP}/hugo.deb" \
"https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb"
sudo dpkg -i "${RUNNER_TEMP}/hugo.deb"
- name: Build
shell: bash
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: ${{ inputs.mode == 'production' && 'production' || 'development' }}
BASE_URL: ${{ inputs.base-url }}
WORKDIR: ${{ inputs.working-directory }}
MODE: ${{ inputs.mode }}
run: |
set -euo pipefail
cd "${WORKDIR}"
args=(--gc --minify --baseURL "${BASE_URL}")
if [ "${MODE}" = "preview" ]; then
args+=(--buildDrafts --buildFuture)
fi
hugo "${args[@]}"