Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: environment variable build context filtering fix #5887

Open
wants to merge 6 commits into
base: main
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
6 changes: 3 additions & 3 deletions packages/config/src/env/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const getEnvelope = async function ({
try {
const environmentVariables = await (api as any).getEnvVars({ accountId, siteId, context_name: context })

const sortedEnvVarsFromDevContext = environmentVariables
const sortedEnvVarsFromContext = environmentVariables
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
.reduce((acc, cur) => {
const envVar = cur.values.find((val) => ['dev', 'all'].includes(val.context))
const envVar = cur.values.find((val) => ['all', context].includes(val.context))
if (envVar && envVar.value) {
return {
...acc,
Expand All @@ -29,7 +29,7 @@ export const getEnvelope = async function ({
}
return acc
}, {})
return sortedEnvVarsFromDevContext
return sortedEnvVarsFromContext
} catch {
return {}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/env/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const getAccountEnv = async function ({
context?: string
}) {
if (siteInfo.use_envelope) {
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, context })
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId: siteInfo.site_id, context })
return envelope
}
const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/tests/env/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ test('Sets environment variables when configured to use Envelope', async (t) =>
t.deepEqual(env.URL.sources, ['general'])
t.is(env.URL.value, 'test')
t.is(env.SHARED_ENV_VAR.value, 'ENVELOPE_TEAM_ALL')
t.is(env.SITE_ENV_VAR.value, 'ENVELOPE_SITE_DEV')
t.is(env.SITE_ENV_VAR.value, 'ENVELOPE_SITE_PROD')
t.is(env.MONGO_ENV_VAR, undefined)
})

Expand Down
Loading