From e8ede35dd1c8195c1e646c46f792ec7912af0bc1 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 3 May 2023 15:59:11 -0230 Subject: [PATCH] Ensure we can successfully create prod builds with specific types (#18991) --- development/build/config.js | 20 ++++++++------------ development/build/scripts.js | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/development/build/config.js b/development/build/config.js index d318b5a88..d8a339de2 100644 --- a/development/build/config.js +++ b/development/build/config.js @@ -7,15 +7,11 @@ const { loadBuildTypesConfig } = require('../lib/build-type'); const { Variables } = require('../lib/variables'); const { ENVIRONMENT } = require('./constants'); -const VARIABLES_REQUIRED_IN_PRODUCTION = [ - 'INFURA_BETA_PROJECT_ID', - 'INFURA_FLASK_PROJECT_ID', - 'INFURA_PROD_PROJECT_ID', - 'SEGMENT_BETA_WRITE_KEY', - 'SEGMENT_FLASK_WRITE_KEY', - 'SEGMENT_PROD_WRITE_KEY', - 'SENTRY_DSN', -]; +const VARIABLES_REQUIRED_IN_PRODUCTION = { + main: ['INFURA_PROD_PROJECT_ID', 'SEGMENT_PROD_WRITE_KEY', 'SENTRY_DSN'], + beta: ['INFURA_BETA_PROJECT_ID', 'SEGMENT_BETA_WRITE_KEY', 'SENTRY_DSN'], + flask: ['INFURA_FLASK_PROJECT_ID', 'SEGMENT_FLASK_WRITE_KEY', 'SENTRY_DSN'], +}; async function fromIniFile(filepath) { let configContents = ''; @@ -137,9 +133,9 @@ async function getConfig(buildType, environment) { // TODO(ritave): Move build targets and environments to builds.yml if (environment === ENVIRONMENT.PRODUCTION) { - const undefinedVariables = VARIABLES_REQUIRED_IN_PRODUCTION.filter( - (variable) => !variables.isDefined(variable), - ); + const undefinedVariables = VARIABLES_REQUIRED_IN_PRODUCTION[ + buildType + ].filter((variable) => !variables.isDefined(variable)); if (undefinedVariables.length !== 0) { const message = `Some variables required to build production target are not defined. - ${undefinedVariables.join('\n - ')} diff --git a/development/build/scripts.js b/development/build/scripts.js index bb217c503..8f65f863c 100644 --- a/development/build/scripts.js +++ b/development/build/scripts.js @@ -126,7 +126,7 @@ function getInfuraProjectId({ buildType, variables, environment, testing }) { return variables.get('INFURA_PROJECT_ID'); } /** @type {string|undefined} */ - const infuraKeyReference = process.env.INFURA_ENV_KEY_REF; + const infuraKeyReference = variables.get('INFURA_ENV_KEY_REF'); assert( typeof infuraKeyReference === 'string' && infuraKeyReference.length > 0, `Build type "${buildType}" has improperly set INFURA_ENV_KEY_REF in builds.yml. Current value: "${infuraKeyReference}"`, @@ -155,7 +155,7 @@ function getSegmentWriteKey({ buildType, variables, environment }) { return variables.get('SEGMENT_WRITE_KEY'); } - const segmentKeyReference = process.env.SEGMENT_WRITE_KEY_REF; + const segmentKeyReference = variables.get('SEGMENT_WRITE_KEY_REF'); assert( typeof segmentKeyReference === 'string' && segmentKeyReference.length > 0, `Build type "${buildType}" has improperly set SEGMENT_WRITE_KEY_REF in builds.yml. Current value: "${segmentKeyReference}"`,