From 2451a7372091791fbbbc110f84152c3677d5b3f8 Mon Sep 17 00:00:00 2001 From: Den Delimarsky Date: Wed, 11 Mar 2026 20:30:44 +0000 Subject: [PATCH] Add hugo-build composite action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- README.md | 1 + hugo-build/README.md | 62 ++++++++++++++++++++++++++++++++++++++ hugo-build/action.yml | 70 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 hugo-build/README.md create mode 100644 hugo-build/action.yml diff --git a/README.md b/README.md index 8d45f42..c754067 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,5 @@ GitHub Actions relevant to the management of MCP repositories. |---|---| | [`cloudflare-pages-preview/deploy`](cloudflare-pages-preview/README.md) | Deploy a static HTML directory to Cloudflare Pages under a per-PR branch alias, inject noindex headers, and post a sticky PR comment with preview URLs | | [`cloudflare-pages-preview/cleanup`](cloudflare-pages-preview/README.md) | Delete Cloudflare Pages deployments for a closed PR's branch alias and update the sticky comment | +| [`hugo-build`](hugo-build/README.md) | Install Go + Hugo extended and build a Hugo site (preview or production mode) | | [`slash-commands`](slash-commands/README.md) | Handle `/lgtm`, `/hold`, and `/stageblog` PR slash commands gated by team membership + CODEOWNERS; invalidate approval on push | diff --git a/hugo-build/README.md b/hugo-build/README.md new file mode 100644 index 0000000..2aa87fe --- /dev/null +++ b/hugo-build/README.md @@ -0,0 +1,62 @@ +# hugo-build + +Installs Go + Hugo (extended edition) and builds a Hugo site. Preview mode +includes drafts and future-dated posts; production mode does not. + +## What it does + +1. Sets up Go (for Hugo modules) +2. Downloads and installs Hugo extended from GitHub releases +3. Runs `hugo --gc --minify --baseURL ` in the working directory, + adding `--buildDrafts --buildFuture` when `mode: preview` + +Output lands in `/public`. + +## Prerequisites + +- The caller must have already checked out the Hugo site source. This action + does **not** run `actions/checkout`. + +## Required secrets + +None. + +## Caller workflow requirements + +| | | +|---|---| +| **Permissions** | `contents: read` (for checkout, not for this action) | +| **Checkout** | Caller must checkout before calling | + +## Usage + +```yaml +- uses: actions/checkout@v6 + with: + submodules: recursive + fetch-depth: 0 + +- uses: modelcontextprotocol/actions/hugo-build@main + with: + working-directory: blog + mode: preview # or: production + base-url: / +``` + +Then deploy `blog/public` however you like (Cloudflare Pages, GitHub Pages, etc.) + +## Inputs + +| Input | Required | Default | Description | +|---|---|---|---| +| `working-directory` | | `.` | Directory containing `hugo.toml` | +| `mode` | | `preview` | `preview` → development env, `--buildDrafts --buildFuture`. `production` → production env, no drafts/future. | +| `base-url` | | `/` | Hugo `--baseURL` | +| `hugo-version` | | `0.148.0` | Hugo extended version | +| `go-version` | | `1.24` | Go version for Hugo modules | + +## Outputs + +| Output | Description | +|---|---| +| `public-dir` | Path to built site (`/public`) | diff --git a/hugo-build/action.yml b/hugo-build/action.yml new file mode 100644 index 0000000..7b6ee84 --- /dev/null +++ b/hugo-build/action.yml @@ -0,0 +1,70 @@ +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[@]}"