From e0f59ec7b79e1534ccda68b60f57dad7fa72ca2d Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Mon, 2 Feb 2026 00:47:18 +0530 Subject: [PATCH] fix(GHA): add critical vars to turbo (#65640) --- client/tools/turbo-env.test.ts | 58 ++++++++++++++++++++++++++++++++++ client/turbo.json | 21 +++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 client/tools/turbo-env.test.ts diff --git a/client/tools/turbo-env.test.ts b/client/tools/turbo-env.test.ts new file mode 100644 index 00000000000..8947dcef975 --- /dev/null +++ b/client/tools/turbo-env.test.ts @@ -0,0 +1,58 @@ +import { describe, test, expect } from 'vitest'; +import * as fs from 'fs'; +import * as path from 'path'; + +describe('turbo.json env configuration', () => { + test('setup task should include all env vars used by read-env.ts', () => { + const readEnvPath = path.resolve(__dirname, 'read-env.ts'); + const turboJsonPath = path.resolve(__dirname, '../turbo.json'); + + const readEnvContent = fs.readFileSync(readEnvPath, 'utf-8'); + const turboJson = JSON.parse(fs.readFileSync(turboJsonPath, 'utf-8')) as { + tasks?: { setup?: { env?: string[] } }; + }; + + // Extract env var names from read-env.ts destructuring pattern + // Matches patterns like: HOME_LOCATION: homeLocation, or just HOME_LOCATION, + const envVarPattern = /(\b[A-Z][A-Z0-9_]+)(?::\s*\w+)?[,\s]/g; + const processEnvSection = readEnvContent.match( + /const\s*\{[\s\S]*?\}\s*=\s*process\.env/ + ); + + if (!processEnvSection) { + throw new Error( + 'Could not find process.env destructuring in read-env.ts' + ); + } + + const envVarsInReadEnv: string[] = []; + let match; + while ((match = envVarPattern.exec(processEnvSection[0])) !== null) { + envVarsInReadEnv.push(match[1]); + } + + // Get env array from turbo.json setup task + const setupEnv = turboJson?.tasks?.setup?.env || []; + + // Check if FCC_* wildcard is present (which covers FCC_ prefixed vars) + const hasFccWildcard = setupEnv.includes('FCC_*'); + + // Filter out FCC_ prefixed vars if wildcard is present + const requiredVars = envVarsInReadEnv.filter( + v => !(hasFccWildcard && v.startsWith('FCC_')) + ); + + const missingVars = requiredVars.filter(v => !setupEnv.includes(v)); + + // Provide a detailed error message if vars are missing + if (missingVars.length > 0) { + throw new Error( + `Missing env vars in client/turbo.json setup.env: ${missingVars.join(', ')}\n` + + `These variables are used in read-env.ts but not passed through by Turborepo.\n` + + `Add them to client/turbo.json tasks.setup.env array.` + ); + } + + expect(missingVars).toEqual([]); + }); +}); diff --git a/client/turbo.json b/client/turbo.json index a2f8ca5117d..44e87207be0 100644 --- a/client/turbo.json +++ b/client/turbo.json @@ -10,7 +10,26 @@ "env": ["FCC_*"] }, "setup": { - "env": ["FCC_*"], + "env": [ + "FCC_*", + "HOME_LOCATION", + "API_LOCATION", + "FORUM_LOCATION", + "NEWS_LOCATION", + "RADIO_LOCATION", + "CLIENT_LOCALE", + "CURRICULUM_LOCALE", + "ALGOLIA_APP_ID", + "ALGOLIA_API_KEY", + "STRIPE_PUBLIC_KEY", + "PAYPAL_CLIENT_ID", + "PATREON_CLIENT_ID", + "DEPLOYMENT_ENV", + "SHOW_UPCOMING_CHANGES", + "GROWTHBOOK_URI", + "DEPLOYMENT_VERSION", + "FREECODECAMP_NODE_ENV" + ], "outputs": [ "config/env.json", "i18n/locales/*.json",