Skip to content

Commit

Permalink
fix: environment variable build context filtering fix (#5887)
Browse files Browse the repository at this point in the history
* build: initial commit

initial commit

Co-authored-by: Thomas Lane <[email protected]>

* fix: build getEnvelope context

fixed issue where build was not injecting env variables that were not dev or all context

Co-authored-by: Thomas Lane <[email protected]>

* fix: fixed test that was failing

Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>

---------

Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Daniel Lew <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2024
1 parent bd49305 commit c0ab547
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
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

0 comments on commit c0ab547

Please sign in to comment.