Skip to content

Inject Netlify VITE_* env into the GH Actions deploy build - #2

Merged
borland667 merged 1 commit into
mainfrom
ops/fix-deploy-env-injection
Jun 14, 2026
Merged

Inject Netlify VITE_* env into the GH Actions deploy build#2
borland667 merged 1 commit into
mainfrom
ops/fix-deploy-env-injection

Conversation

@borland667

Copy link
Copy Markdown
Owner

Summary

PR #1 moved the production build into GitHub Actions but inadvertently regressed the frontend env injection: npm run build in CI runs without Netlify's project env, so the deployed bundle was shipped with empty VITE_POSTHOG_KEY, VITE_ANALYTICS_ENABLED, VITE_ANALYTICS_PROVIDER, VITE_POSTHOG_HOST, and VITE_GOOGLE_CLIENT_ID. Result: PostHog analytics were silently dead in production.

Verified by grep-ing the live index-CB3pNDaH.js bundle for the configured PostHog key — not present, despite the Netlify project env having it set.

Fix

Use netlify deploy --prod --build instead of npm run build + netlify deploy --dir dist. The --build flag invokes netlify build, which loads Netlify's project env into the Vite build process so all VITE_* values are baked into the bundle.

Source of truth for env stays where it should be:

Env scope Where it lives How it reaches code
Frontend (VITE_*) Netlify project env netlify build injects at build time
Backend runtime Netlify project env Netlify Functions injects at request time
GH Actions auth GH repo secrets Only NETLIFY_AUTH_TOKEN, NETLIFY_SITE_ID, PRODUCTION_DATABASE_URL

What this also cleans up

  • Removed explicit db:generate step — already covered by the postinstall hook that runs npx prisma generate after npm ci.
  • Removed explicit Build site step — folded into netlify deploy --build.
  • ARCHITECTURE.md §15.4: updated the pipeline contract, added explicit notes that --build and --skip-functions-cache are both mandatory, and noted Netlify's git auto-deploy is disabled (stop_builds: true).

Test plan

  • YAML parses cleanly (steps: checkout → setup-node → install → deploy → smoke check)
  • On merge: deploy-production job goes green
  • Live bundle contains the PostHog key (grep for SStrVZFix)
  • PostHog dashboard receives events from the deployed site

Made with Cursor

The previous deploy step ran `npm run build` directly, which had no
access to the Netlify project env vars. As a result the production
bundle shipped with empty `VITE_POSTHOG_KEY`, `VITE_ANALYTICS_ENABLED`,
`VITE_ANALYTICS_PROVIDER`, `VITE_POSTHOG_HOST`, and
`VITE_GOOGLE_CLIENT_ID`, silently disabling analytics in production.

Switching to `netlify deploy --prod --build` runs `netlify build`
first, which pulls the Netlify project env into the Vite build so
those values are baked into the deployed bundle. Source of truth for
frontend env stays in Netlify's project env, not in GitHub secrets.

Also drops the explicit `db:generate` step (already covered by the
`postinstall` hook that runs `npx prisma generate`) and the explicit
`Build site` step (now part of `--build`).

ARCHITECTURE.md §15.4 updated with the new contract and a note that
Netlify's git auto-deploy is now disabled (stop_builds: true), so the
GitHub Actions deploy is the only path to production.

Co-authored-by: Cursor <cursoragent@cursor.com>
@borland667
borland667 merged commit 18a3b3f into main Jun 14, 2026
6 checks passed
@borland667
borland667 deleted the ops/fix-deploy-env-injection branch June 14, 2026 19:21
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.

1 participant