Set HUGO_ENVIRONMENT=preview for PR-preview builds#1027
Open
ppiegaze wants to merge 2 commits into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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
envblock on the "Build dist" step that setsHUGO_ENVIRONMENTtopreviewforpull_requestevents andproductionotherwise.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
GHA build & deploy previewBuilt by
Updated automatically on every push. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make distinvokes rawhugo(viarun_hugo.sh) with no--environmentflag. Hugo's build command defaults to theproductionenvironment, so PR previews and production deploys are indistinguishable to templates —hugo.IsProductionistruefor both.HUGO_ENVIRONMENT=previewonpull_requestevents inbuild-and-deploy.yml. Push-to-main remainsproduction.{{ if not hugo.IsProduction }}and should appear on PR previews but not ondocs.union.ai. Without this change, the gate silences the embed everywhere except localmake dev.hugo.IsProductionhaving its intended meaning.Test plan
HUGO_ENVIRONMENT=previewis set duringmake dist.HUGO_ENVIRONMENT(or showsproduction).docs.union.ai.🤖 Generated with Claude Code