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

(BSR) ci(env): check variables in env files #6318

Merged
merged 4 commits into from
Apr 24, 2024
Merged
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
34 changes: 32 additions & 2 deletions .env.integration
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ APP_PUBLIC_URL=https://integration.passculture.app
# Feature Toggling
FEATURE_FLIPPING_ONLY_VISIBLE_ON_TESTING=false

APP_DISPLAY_NAME="NOT USED IN INTEGRATION ENVIRONMENT"

# iOS
IOS_APP_ID="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_APP_NAME="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_PROVISIONING_PROFILE_SPECIFIER_DEVELOPMENT="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_PROVISIONING_PROFILE_SPECIFIER_RELEASE="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_TEAM_ID="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_APP_ICON="NOT USED IN INTEGRATION ENVIRONMENT"
IOS_APP_STORE_ID="NOT USED IN INTEGRATION ENVIRONMENT"

# Android
ANDROID_APP_ID="NOT USED IN INTEGRATION ENVIRONMENT"
ANDROID_APP_NAME="NOT USED IN INTEGRATION ENVIRONMENT"

# CodePush
CODEPUSH_KEY_IOS="NOT USED IN INTEGRATION ENVIRONMENT"
CODEPUSH_KEY_ANDROID="NOT USED IN INTEGRATION ENVIRONMENT"
CODEPUSH_DEPLOYMENT_NAME="NOT USED IN INTEGRATION ENVIRONMENT"

# Sentry
SENTRY_DSN='https://cbc513d8ef954df7910196a236ed3b6c@sentry.passculture.team/6'
SENTRY_PROFILES_SAMPLE_RATE=0.25
Expand All @@ -30,6 +50,10 @@ EDUCONNECT_ALLOWED_DOMAIN=https://pr4.educonnect.phm.education.gouv.fr
URL_PREFIX=passculture
FIREBASE_DYNAMIC_LINK_DOMAIN=passcultureappintegration.page.link

# Batch
BATCH_API_KEY_IOS="NOT USED IN INTEGRATION ENVIRONMENT"
BATCH_API_KEY_ANDROID="NOT USED IN INTEGRATION ENVIRONMENT"

# Contentful
CONTENTFUL_ACCESS_TOKEN=NazW0Gl-T5S45ZDPRpbS_35KKIvgXrMG2DE3P2i-7fQ
CONTENTFUL_ENVIRONMENT=testing
Expand All @@ -47,6 +71,7 @@ ALGOLIA_VENUES_INDEX_PLAYLIST_SEARCH=venues playlist search

# Support
SUPPORT_EMAIL_ADDRESS=support@passculture.app
FRAUD_EMAIL_ADDRESS=service.fraude@passculture.app
DOC_CGU_URL=https://docs.passculture.app/textes-normatifs/mentions-legales-et-conditions-generales-dutilisation-de-lapplication-pass-culture
DOC_PERSONAL_DATA_URL=https://docs.passculture.app/textes-normatifs/charte-des-donnees-personnelles
CGU_LINK=https://pass.culture.fr/cgu/
Expand All @@ -62,6 +87,8 @@ FAQ_LINK_SIGNUP_CONFIRMATION_EMAIL_NOT_RECEIVED=https://passculture.zendesk.com/
ACCESSIBILITY_LINK=https://pass.culture.fr/accessibilite-de-la-webapp/
DATA_PRIVACY_CHART_LINK=https://pass.culture.fr/donnees-personnelles/
DSM_URL=https://www.demarches-simplifiees.fr/commencer/inscription-pass-culture
DMS_FRENCH_CITIZEN_URL=https://www.demarches-simplifiees.fr/commencer/demande-pass-culture-fr
DMS_FOREIGN_CITIZEN_URL=https://www.demarches-simplifiees.fr/commencer/demande-pass-culture-et
BOOKING_LIMIT_EXCEEDED_URL=https://aide.passculture.app/hc/fr/articles/4411991975825

# Recommendation algorithm
Expand All @@ -81,7 +108,7 @@ FIREBASE_MESSAGINGSENDERID=605788939445
FIREBASE_APPID=1:605788939445:web:4ad37ad33081228e29cafc

# Amplitude
AMPLITUDE_API_KEY=
AMPLITUDE_API_KEY="NOT USED IN INTEGRATION ENVIRONMENT"

# Stores
APPLE_STORE_URL=https://apps.apple.com/fr/app/pass-culture/id1557887412
Expand All @@ -94,4 +121,7 @@ TUTORIAL_FEEDBACK_LINK=https://passculture.qualtrics.com/jfe/form/SV_8rkHZvOvmtd
# Google SSO
GOOGLE_CLIENT_ID=605788939445-jbn4bv8q35gdpmg777pfcu055j4ltf4f.apps.googleusercontent.com
GOOGLE_IOS_CLIENT_ID=605788939445-ao0ttechrkauop1fbmlnac3gqrjgtp5u.apps.googleusercontent.com
GOOGLE_IOS_REVERSED_CLIENT_ID=com.googleusercontent.apps.605788939445-ao0ttechrkauop1fbmlnac3gqrjgtp5u
GOOGLE_IOS_REVERSED_CLIENT_ID=com.googleusercontent.apps.605788939445-ao0ttechrkauop1fbmlnac3gqrjgtp5u

# Google Maps SDK
GOOGLE_MAPS_API_KEY="NOT USED IN INTEGRATION ENVIRONMENT"
47 changes: 0 additions & 47 deletions scripts/detect_ko_test.py

This file was deleted.

49 changes: 49 additions & 0 deletions src/noMissingVariablesInEnvFiles.native.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { config } from 'dotenv'

function loadEnvVariables(filePath: string) {
const { parsed, error } = config({ path: filePath })
if (error) {
throw error
}
if (!parsed) {
throw new Error(`No variables found in ${filePath}`)
}

return Object.keys(parsed)
}

function compareEnvFiles(envFiles: string[]) {
const envData: Record<string, string[]> = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai l'impression qu'il pourrait etre intéressant d'avoir un Set en valeur

Suggested change
const envData: Record<string, string[]> = {}
const envData: Record<string, Set<string>> = {}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si on avait la méthode Set.union et Set.symetricDifference, carrément, mais ce n'est pas le cas en NodeJS, donc c'est + simple avec un array :/

envFiles.forEach((file) => {
envData[file] = loadEnvVariables(file)
})

const allKeys = new Set<string>()
for (const data of Object.values(envData)) {
for (const key of data) {
allKeys.add(key)
}
}

const missing: Record<string, string[]> = {}
for (const [file, data] of Object.entries(envData)) {
missing[file] = Array.from(allKeys).filter((x) => !data.includes(x))
}
Comment on lines +28 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les Set ont des méthodes pour les comparer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set_composition

j'ai l'impression que A.symmetricDifference(B) répondrait au besoin

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça risque d'être compliqué : c'est pas dispo en Node !
image


return missing
}

describe('.env files', () => {
const envFiles = ['.env.testing', '.env.staging', '.env.integration', '.env.production']

test('all variables should be present in all .env files', () => {
const missingVariables = compareEnvFiles(envFiles)
for (const [file, variables] of Object.entries(missingVariables)) {
if (variables.length > 0) {
throw new Error(`Missing variables in ${file}: ${variables.join(', ')}`)
}
}

expect(true).toBe(true) // Pass if no error is thrown
})
})
Loading