Skip to content

fix: build type env vars#7372

Merged
alfetopito merged 24 commits into
developfrom
fix/build-envs
May 12, 2026
Merged

fix: build type env vars#7372
alfetopito merged 24 commits into
developfrom
fix/build-envs

Conversation

@alfetopito

@alfetopito alfetopito commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Sets up new env vars for the 3 apps:

  • cow.fi: NEXT_PUBLIC_ENVIRONMENT
  • cowswap: REACT_APP_ENVIRONMENT
  • explorer: REACT_APP_ENVIRONMENT

It replaces the existing way of identifying the app via URL regex which is error prone and hard to test.
The app should fail to start if it's not set.

To Test

Cow.fi

  1. Open the console.
  • There should be a log [cow-fi][environment] with the env pr.

Explorer

  1. Open the console.
  • There should be a log [explorer][environment] with the env pr.

Cowswap

  1. Open the console.
  • There should be a log [COW][Default] with the env pr.

Further testing to be done once the app reaches the appropriated envs OR locally by setting the env vars to the respective values

Summary by CodeRabbit

  • New Features

    • Apps now use explicit environment variables for selecting runtime environments (replacing hostname inference).
  • Documentation

    • README and app docs updated with supported environment values and .env examples.
  • Bug Fixes

    • Removed forced production settings from some environment files.
  • Chores

    • Removed deprecated "barn" build configuration.
    • CI/workflow and deploy configs now expose a unified environment variable for frontend builds.

@vercel

vercel Bot commented Apr 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview May 12, 2026 4:12pm
explorer-dev Ready Ready Preview May 12, 2026 4:12pm
storybook Ready Ready Preview May 12, 2026 4:12pm
swap-dev Ready Ready Preview May 12, 2026 4:12pm
widget-configurator Ready Ready Preview May 12, 2026 4:12pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored May 12, 2026 4:12pm
sdk-tools Ignored Ignored Preview May 12, 2026 4:12pm

Request Review

@alfetopito alfetopito self-assigned this Apr 16, 2026
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dc49a958-2a5c-4c07-bafd-29aaa7e539f8

📥 Commits

Reviewing files that changed from the base of the PR and between ceac06b and 86967f0.

📒 Files selected for processing (36)
  • .github/workflows/ipfs.yml
  • .github/workflows/vercel.yml
  • README.md
  • apps/cow-fi/.env
  • apps/cow-fi/.env.example
  • apps/cow-fi/README.md
  • apps/cow-fi/app/layout.tsx
  • apps/cow-fi/app/providers.tsx
  • apps/cow-fi/app/robots.ts
  • apps/cow-fi/middleware.ts
  • apps/cow-fi/next.config.ts
  • apps/cow-fi/util/environment.ts
  • apps/cow-fi/util/environments.test.ts
  • apps/cowswap-frontend/.env.barn
  • apps/cowswap-frontend/.env.dev
  • apps/cowswap-frontend/.env.development
  • apps/cowswap-frontend/.env.production
  • apps/cowswap-frontend/.env.staging
  • apps/cowswap-frontend/jest.setup.ts
  • apps/cowswap-frontend/project.json
  • apps/explorer/.env
  • apps/explorer/.env.barn
  • apps/explorer/.env.dev
  • apps/explorer/.env.example
  • apps/explorer/.env.production
  • apps/explorer/.env.staging
  • apps/explorer/README.md
  • apps/explorer/project.json
  • apps/explorer/src/test/utils/env.test.ts
  • apps/explorer/src/utils/env.ts
  • jest.setup.ts
  • libs/common-utils/src/env.ts
  • libs/common-utils/src/environments.test.ts
  • libs/common-utils/src/environments.ts
  • libs/ui/src/containers/Footer/index.tsx
  • libs/ui/src/index.ts
💤 Files with no reviewable changes (4)
  • apps/explorer/project.json
  • apps/explorer/.env.barn
  • apps/cowswap-frontend/.env.barn
  • apps/cowswap-frontend/project.json
✅ Files skipped from review due to trivial changes (16)
  • apps/explorer/.env.production
  • apps/cowswap-frontend/.env.dev
  • apps/explorer/.env.dev
  • apps/explorer/.env
  • apps/cow-fi/.env
  • apps/cow-fi/README.md
  • apps/cowswap-frontend/.env.production
  • apps/cowswap-frontend/.env.staging
  • apps/cow-fi/.env.example
  • apps/explorer/README.md
  • .github/workflows/ipfs.yml
  • apps/explorer/.env.staging
  • apps/cowswap-frontend/.env.development
  • libs/ui/src/containers/Footer/index.tsx
  • apps/explorer/.env.example
  • README.md
🚧 Files skipped from review as they are similar to previous changes (15)
  • .github/workflows/vercel.yml
  • jest.setup.ts
  • apps/cow-fi/app/providers.tsx
  • libs/ui/src/index.ts
  • apps/cow-fi/app/robots.ts
  • apps/explorer/src/utils/env.ts
  • apps/cow-fi/next.config.ts
  • libs/common-utils/src/environments.test.ts
  • apps/cow-fi/middleware.ts
  • apps/explorer/src/test/utils/env.test.ts
  • apps/cow-fi/app/layout.tsx
  • apps/cowswap-frontend/jest.setup.ts
  • libs/common-utils/src/environments.ts
  • apps/cow-fi/util/environments.test.ts
  • apps/cow-fi/util/environment.ts

Walkthrough

This PR replaces hostname/regex-based environment detection with explicit configuration via REACT_APP_ENVIRONMENT and NEXT_PUBLIC_ENVIRONMENT, updates app/build/workflow wiring to read those vars, adjusts Next.js server/middleware/routes to call parameterless checks, and updates tests/docs accordingly. (≤50 words)

Changes

Environment configuration & shared utilities

Layer / File(s) Summary
Env resolution helper
libs/common-utils/src/env.ts
Adds getConfiguredEnvironmentNameFromEnvVars to normalize/validate env var values from candidates (REACT_APP_ENVIRONMENT, NEXT_PUBLIC_ENVIRONMENT, NODE_ENV) and throw on missing/invalid values.
Shared environments module
libs/common-utils/src/environments.ts
Replaces host/regex detection with config-driven flow: defines EnvironmentName and ALL_ENVIRONMENTS, makes checkEnvironment() parameterless returning EnvironmentChecks, derives boolean flags from the configured name, and ensures environmentName is always a concrete EnvironmentName.
Tests for shared logic
libs/common-utils/src/environments.test.ts
Rewrites tests to set/reset env var, dynamically import module, assert missing/invalid error behavior, and validate flags for each allowed environment.

App-specific environment adoption

Layer / File(s) Summary
Cow‑fi config + docs
apps/cow-fi/.env, apps/cow-fi/.env.example, apps/cow-fi/README.md
Adds NEXT_PUBLIC_ENVIRONMENT entries and documents supported values; updates .env example and README to require explicit environment selection.
Cow‑fi runtime wiring
apps/cow-fi/util/environment.ts, apps/cow-fi/app/layout.tsx, apps/cow-fi/app/robots.ts, apps/cow-fi/middleware.ts, apps/cow-fi/next.config.ts, apps/cow-fi/app/providers.tsx
Changes environment detection to use NEXT_PUBLIC_ENVIRONMENT via validated config; removes next/headers host inspection; updates Next config to expose and DefinePlugin-replace both REACT_APP_ENVIRONMENT and NEXT_PUBLIC_ENVIRONMENT; adds explicit return types and optional clearTag?.() call.
Cow‑fi tests
apps/cow-fi/util/environments.test.ts
Reworks tests to drive module behavior via process.env.NEXT_PUBLIC_ENVIRONMENT, resetting modules between cases and asserting error/flag outcomes.

Explorer adoption

Layer / File(s) Summary
Explorer env module
apps/explorer/src/utils/env.ts
Switches to config-driven detection using REACT_APP_ENVIRONMENT allowlist; exports checkEnvironment() and guarantees environmentName as a typed Envs; adds isLocal/isPr flags.
Explorer .env/docs/tests
apps/explorer/.env*, apps/explorer/README.md, apps/explorer/src/test/utils/env.test.ts
Adds REACT_APP_ENVIRONMENT to env files and example; documents allowed values; adds tests that import module dynamically and assert missing/invalid error cases and correct flag outputs.

Cowswap frontend & test harness

Layer / File(s) Summary
Frontend .env updates
apps/cowswap-frontend/.env.*, apps/cowswap-frontend/jest.setup.ts, jest.setup.ts
Adds REACT_APP_ENVIRONMENT declarations across env files; removes barn NODE_ENV forcing; updates Jest setup(s) to load additional app .env files and set REACT_APP_ENVIRONMENT for cowswap-frontend tests at runtime.
Project config
apps/cowswap-frontend/project.json, apps/explorer/project.json
Removes barn build configuration entries from project build targets.

Workflows, exports, minor tweaks

Layer / File(s) Summary
CI/workflows
.github/workflows/ipfs.yml, .github/workflows/vercel.yml
Adds REACT_APP_ENVIRONMENT env definitions in workflows (IPFS: ens; Vercel: mapping from inputs.env_name to production/development/pass-through).
UI package export & minor reorder
libs/ui/src/index.ts, libs/ui/src/containers/Footer/index.tsx
Adds named re-export getGlobalFooterNavItems and reorders destructured imports (non-functional).

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer/CI
    participant Build as Build (Webpack/Vercel)
    participant Next as Next.js Server (middleware/routes)
    participant Browser as Browser/Client
    participant EnvLib as libs/common-utils

    Dev->>Build: Provide env (REACT_APP_ENVIRONMENT / NEXT_PUBLIC_ENVIRONMENT)
    Build->>EnvLib: getConfiguredEnvironmentNameFromEnvVars() (at build/test time)
    Build->>Next: webpack.DefinePlugin inlines configuredEnvironment
    Browser->>Next: Request (middleware/robots/layout call checkEnvironment())
    Next->>EnvLib: checkEnvironment() (parameterless, uses configured value)
    EnvLib-->>Next: Environment flags (isProd/isDev/isPr/isLocal/isStaging)
    Next-->>Browser: Response with X-Robots-Tag / metadata / rendered page
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit nibbles env vars, neat and spry,
Host-magic gone — now names that certify.
Flags uncurl, tests hop through each case,
Build and server know their proper place. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: build type env vars' clearly summarizes the main change: introducing and fixing environment variable configuration for builds.
Description check ✅ Passed The description includes a clear summary of what env vars are added for each app, explains the motivation (replacing error-prone URL regex detection), and provides comprehensive testing instructions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/build-envs

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants