Inject Netlify VITE_* env into the GH Actions deploy build - #2
Merged
Conversation
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>
3 tasks
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
PR #1 moved the production build into GitHub Actions but inadvertently regressed the frontend env injection:
npm run buildin CI runs without Netlify's project env, so the deployed bundle was shipped with emptyVITE_POSTHOG_KEY,VITE_ANALYTICS_ENABLED,VITE_ANALYTICS_PROVIDER,VITE_POSTHOG_HOST, andVITE_GOOGLE_CLIENT_ID. Result: PostHog analytics were silently dead in production.Verified by grep-ing the live
index-CB3pNDaH.jsbundle for the configured PostHog key — not present, despite the Netlify project env having it set.Fix
Use
netlify deploy --prod --buildinstead ofnpm run build+netlify deploy --dir dist. The--buildflag invokesnetlify build, which loads Netlify's project env into the Vite build process so allVITE_*values are baked into the bundle.Source of truth for env stays where it should be:
VITE_*)netlify buildinjects at build timeNETLIFY_AUTH_TOKEN,NETLIFY_SITE_ID,PRODUCTION_DATABASE_URLWhat this also cleans up
db:generatestep — already covered by thepostinstallhook that runsnpx prisma generateafternpm ci.Build sitestep — folded intonetlify deploy --build.--buildand--skip-functions-cacheare both mandatory, and noted Netlify's git auto-deploy is disabled (stop_builds: true).Test plan
deploy-productionjob goes greenSStrVZFix)Made with Cursor