Skip to content

Set HUGO_ENVIRONMENT=preview for PR-preview builds#1027

Open
ppiegaze wants to merge 2 commits into
mainfrom
peeter/hugo-preview-environment-main
Open

Set HUGO_ENVIRONMENT=preview for PR-preview builds#1027
ppiegaze wants to merge 2 commits into
mainfrom
peeter/hugo-preview-environment-main

Conversation

@ppiegaze

Copy link
Copy Markdown
Collaborator

Summary

  • make dist invokes raw hugo (via run_hugo.sh) with no --environment flag. Hugo's build command defaults to the production environment, so PR previews and production deploys are indistinguishable to templates — hugo.IsProduction is true for both.
  • This PR sets HUGO_ENVIRONMENT=preview on pull_request events in build-and-deploy.yml. Push-to-main remains production.
  • First consumer: the upcoming Hypothesis annotation embed (annotator project), which is gated on {{ if not hugo.IsProduction }} and should appear on PR previews but not on docs.union.ai. Without this change, the gate silences the embed everywhere except local make dev.
  • Generally useful primitive: any future preview-only feature can now rely on hugo.IsProduction having its intended meaning.

Test plan

  • After merge, push a no-op PR and confirm in the build logs that HUGO_ENVIRONMENT=preview is set during make dist.
  • Confirm production build (push to main) does not log HUGO_ENVIRONMENT (or shows production).
  • Once the annotator Hypothesis embed lands, verify the script tag appears on a PR preview URL and is absent on docs.union.ai.

🤖 Generated with Claude Code

The `hugo` command (used by `make dist`) defaults to the `production`
environment when no `--environment` flag is passed, so PR-preview
builds and production builds were indistinguishable in templates —
`hugo.IsProduction` was true for both.

Pass `HUGO_ENVIRONMENT=preview` on `pull_request` events so templates
can gate non-prod-only features (the Hypothesis annotation embed
is the first user) on `hugo.IsProduction` and have it actually mean
"not a preview build, this is the live site". Production deploys
(push to main) remain `production`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 14, 2026 09:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Sets HUGO_ENVIRONMENT=preview for PR-preview builds in the GitHub Actions workflow so Hugo's hugo.IsProduction correctly distinguishes preview builds from production deploys, enabling preview-only features to be gated properly.

Changes:

  • Add env block on the "Build dist" step that sets HUGO_ENVIRONMENT to preview for pull_request events and production otherwise.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented May 14, 2026

Copy link
Copy Markdown

GHA build & deploy preview

Built by .github/workflows/build-and-deploy.yml and deployed to the docs CF Pages project.

Branch alias https://pr-1027-peeter-hugo-preview.docs-dog.pages.dev
This commit https://7a01082b.docs-dog.pages.dev
Commit SHA 367d50ef4a5d22913c33ccfecff0ad2cbe18da76

Updated automatically on every push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants