Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

fix: baseSchema env validation not working #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
- uses: zerodays/action-infisical@v1
with:
infisical_token: ${{ secrets.INFISICAL_TOKEN }}
environment: "staging"
workspace_id: ${{ secrets.INFISICAL_WORKSPACE_ID }}
environment: 'staging'
- name: Lint
run: |
source .env && pnpm tsc
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: zerodays/action-infisical@v1
with:
infisical_token: ${{ secrets.INFISICAL_TOKEN }}
workspace_id: ${{ secrets.INFISICAL_WORKSPACE_ID }}
environment: 'staging'
- name: Run tests
run: source .env && pnpm jest --reporters="summary" --reporters="github-actions"
22 changes: 16 additions & 6 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ const currentEnv = process.env.NODE_ENV || 'development'; // Default to 'develop
let envSchema;
switch (currentEnv) {
case 'development':
envSchema = { ...baseSchema, ...devSchema };
envSchema = {
server: { ...baseSchema.server, ...devSchema.server },
client: { ...baseSchema.client, ...devSchema.client },
};
break;
case 'test':
case 'staging':
envSchema = { ...baseSchema, ...stagingSchema };
envSchema = {
server: { ...baseSchema.server, ...stagingSchema.server },
client: { ...baseSchema.client, ...stagingSchema.client },
};
break;
case 'production':
envSchema = { ...baseSchema, ...productionSchema };
envSchema = {
server: { ...baseSchema.server, ...productionSchema.server },
client: { ...baseSchema.client, ...productionSchema.client },
};
break;
default:
throw new Error(`Unknown environment: ${currentEnv}`);
}

// Runtime environment variables (for Next.js edge runtimes or client-side)
Expand All @@ -76,7 +83,10 @@ const runtimeEnv = {
};

// Skip env validation flag (useful for Docker builds)
const skipValidation = !!process.env.SKIP_ENV_VALIDATION;
// Also skip on lint, see: https://github.com/t3-oss/t3-env/issues/102
const skipValidation =
!!process.env.SKIP_ENV_VALIDATION ||
process.env.npm_lifecycle_script === 'next lint';

// Treat empty strings as undefined
const emptyStringAsUndefined = true;
Expand Down
Loading