-
Notifications
You must be signed in to change notification settings - Fork 400
fix: wrong env values could be used for non-dev context in netlify deploy --build --context
#5538
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
Changes from all commits
8c8afc7
b558a0d
1315b1a
6f28075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,11 +131,12 @@ export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope | |
* @param {string} context - The deploy context or branch of the environment variable | ||
* @param {object} env - The dictionary of environment variables | ||
* @param {string} key - If present, fetch a single key (case-sensitive) | ||
* @param {boolean} raw - Return a dictionary of raw key/value pairs for only the account and site sources | ||
* @param {enum<any,builds,functions,runtime,post_processing>} scope - The scope of the environment variables | ||
* @param {object} siteInfo - The site object | ||
* @returns {object} An object of environment variables keys and their metadata | ||
*/ | ||
export const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'any', siteInfo }) => { | ||
export const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', raw = false, scope = 'any', siteInfo }) => { | ||
const { account_slug: accountId, id: siteId } = siteInfo | ||
|
||
const [accountEnvelopeItems, siteEnvelopeItems] = await Promise.all([ | ||
|
@@ -145,6 +146,18 @@ export const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scop | |
|
||
const accountEnv = formatEnvelopeData({ context, envelopeItems: accountEnvelopeItems, scope, source: 'account' }) | ||
const siteEnv = formatEnvelopeData({ context, envelopeItems: siteEnvelopeItems, scope, source: 'ui' }) | ||
|
||
if (raw) { | ||
const entries = Object.entries({ ...accountEnv, ...siteEnv }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it correct that only account and site env vars, and not general / addons / configFile env vars, need to be included as siteEnv for the functionsConfig? That's how it seems to be before -- only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think that's right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK cool! then I think this would fix a bug where account-level env vars weren't getting applied to functions if a user deployed with this method. |
||
return entries.reduce( | ||
(obj, [envVarKey, metadata]) => ({ | ||
...obj, | ||
[envVarKey]: metadata.value, | ||
}), | ||
{}, | ||
) | ||
} | ||
|
||
const generalEnv = filterEnvBySource(env, 'general') | ||
const internalEnv = filterEnvBySource(env, 'internal') | ||
const addonsEnv = filterEnvBySource(env, 'addons') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this additional check is unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.context
could beundefined
if the user doesn't pass the--context
flag, but the Envelope call defaults to use thedev
context in that case. So if context isn't passed, or if context isdev
, then we can skip the call. We could remove this bit if we gave the option a default value besides undefined, but I'm unsure if that would be a breaking change!