Fix Cosmic env vars not reaching Vercel runtime#42
Closed
xuvi7 wants to merge 2 commits into
Closed
Conversation
The COSMIC_* and NEXT_PUBLIC_BEHOLD_FEED_URL vars were declared in the GitHub Actions job-level `env:` block. That only feeds `vercel build` in the runner; it never reaches the deployed serverless functions, whose runtime env comes solely from the Vercel project's Environment Variables (injected at deploy time). The result: builds passed while functions threw "Missing COSMIC_BUCKET_SLUG" at runtime, with the env block masking the real misconfiguration. Changes to both preview.yaml and production.yaml: - Drop app secrets from the `env:` block, leaving only VERCEL_ORG_ID and VERCEL_PROJECT_ID (the canonical Vercel CI pattern). `vercel pull` is now the single source of truth, so a misconfig fails the build loudly instead of shipping a broken site. - Add a post-`vercel pull` verification step that prints the pulled key names (values hidden) and hard-fails with a clear error if the Cosmic keys are absent, pinpointing whether the issue is project/token scope. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The previous check matched `KEY=` even when the value was blank, so empty Vercel env values slipped through and then failed `next build` at module evaluation (lib/cosmic.ts treats an empty string as missing). Assert each Cosmic var has a non-empty value after stripping quotes/whitespace. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What & why
Cosmic data fails to load on the deployed site, with serverless functions throwing
Missing COSMIC_BUCKET_SLUGat runtime — even though the env vars are set in both GitHub Secrets and the Vercel project.Root cause:
COSMIC_*andNEXT_PUBLIC_BEHOLD_FEED_URLwere declared in the GitHub Actions job-levelenv:block. That block only feedsvercel buildrunning inside the CI runner; it never reaches the deployed serverless functions. Runtime env for avercel deploy --prebuiltcomes solely from the Vercel project's Environment Variables, injected at deploy time. So the build passed (env present in the runner) while runtime functions had no Cosmic vars — and theenv:block actively masked the real misconfiguration.Changes
Applied to both
preview.yamlandproduction.yaml:env:block, leaving onlyVERCEL_ORG_IDandVERCEL_PROJECT_ID(the canonical Vercel CI pattern).vercel pullis now the single source of truth, so a missing/mis-scoped var fails the build loudly instead of silently shipping a broken site.vercel pullthat prints the pulled key names (values hidden) and hard-fails with a clear::error::if the Cosmic keys are absent — pinpointing whether the problem is project/token scope vs. a stale deployment.Reviewer notes / follow-up
This change makes the failure mode observable; the actual unblock depends on what the new verification step reports:
vercel pullisn't seeing the dashboard vars. Confirm theVERCEL_ORG_ID/VERCEL_PROJECT_IDsecrets andVERCEL_TOKENscope point to the project where the Cosmic vars are set.🤖 Generated with Claude Code