diff --git a/.github/workflows/bitrise-envs-sync.yml b/.github/workflows/bitrise-envs-sync.yml index ced943e055..4c9faf8194 100644 --- a/.github/workflows/bitrise-envs-sync.yml +++ b/.github/workflows/bitrise-envs-sync.yml @@ -37,10 +37,10 @@ jobs: - name: Wrtie envs to files working-directory: packages/core-mobile/scripts/github run: | - ./writeEnvsToFile.sh "$ENV_DEV" ".env.development" - ./writeEnvsToFile.sh "$ENV_DEV_E2E" ".env.development.e2e" - ./writeEnvsToFile.sh "$ENV_PROD" ".env.production" - ./writeEnvsToFile.sh "$ENV_PROD_E2E" ".env.production.e2e" + ../common/writeEnvsToFile.sh "$ENV_DEV" ".env.development" + ../common/writeEnvsToFile.sh "$ENV_DEV_E2E" ".env.development.e2e" + ../common/writeEnvsToFile.sh "$ENV_PROD" ".env.production" + ../common/writeEnvsToFile.sh "$ENV_PROD_E2E" ".env.production.e2e" - name: Upload envs to Bitrise working-directory: packages/core-mobile/scripts/github diff --git a/packages/core-mobile/package.json b/packages/core-mobile/package.json index cdd4d3da31..0d6e5ca89a 100644 --- a/packages/core-mobile/package.json +++ b/packages/core-mobile/package.json @@ -3,6 +3,7 @@ "private": true, "scripts": { "setup": "yarn allow-scripts", + "envs": "./scripts/getEnvs.sh", "android": "ENVFILE=.env.development react-native run-android --variant=internalDebug", "podInstall": "bundle _2.1.4_ install && cd ios && bundle exec pod install", "ios": "ENVFILE=.env.development react-native run-ios", diff --git a/packages/core-mobile/scripts/github/writeEnvsToFile.sh b/packages/core-mobile/scripts/common/writeEnvsToFile.sh similarity index 84% rename from packages/core-mobile/scripts/github/writeEnvsToFile.sh rename to packages/core-mobile/scripts/common/writeEnvsToFile.sh index b872ca7ad9..149dce5913 100755 --- a/packages/core-mobile/scripts/github/writeEnvsToFile.sh +++ b/packages/core-mobile/scripts/common/writeEnvsToFile.sh @@ -10,6 +10,7 @@ fi # Retrieve the env value and assign it to the data variable data=$1 +output_file=$2 # Check if the secret value is empty if [ -z "$data" ]; then @@ -21,11 +22,11 @@ fi pairs=$(echo "$data" | sed 's/[{}"]//g' | tr ',' '\n' | sed 's/:/=/') # Erase the content of the output file -> "$2" +> "$output_file" # Write the key-value pairs to the output file echo "$pairs" | while IFS= read -r line; do - echo "$line" | sed 's/\\//g' >> "$2" + echo "$line" | sed 's/\\//g' >> "$output_file" done -echo "envs saved to $2" \ No newline at end of file +echo "envs saved to $output_file" \ No newline at end of file diff --git a/packages/core-mobile/scripts/getEnvs.sh b/packages/core-mobile/scripts/getEnvs.sh new file mode 100755 index 0000000000..3486c54183 --- /dev/null +++ b/packages/core-mobile/scripts/getEnvs.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# Retrieve secret by id from AWS Secrets Manager +getSecretFromAWS() { + local secret_id="$1" + sudo aws secretsmanager get-secret-value --secret-id "$secret_id" | grep SecretString | sed 's/.*"SecretString": "\(.*\)".*/\1/' +} + +# Retrieve all envs from AWS +ENV_DEV=$(getSecretFromAWS "core/dev/mobile/.env.development") +ENV_DEV_E2E=$(getSecretFromAWS "core/dev/mobile/.env.development.e2e") +ENV_PROD=$(getSecretFromAWS "core/dev/mobile/.env.production") +ENV_PROD_E2E=$(getSecretFromAWS "core/dev/mobile/.env.production.e2e") + +# Write to env files +./scripts/common/writeEnvsToFile.sh "$ENV_DEV" ".env.development" +./scripts/common/writeEnvsToFile.sh "$ENV_DEV_E2E" ".env.development.e2e" +./scripts/common/writeEnvsToFile.sh "$ENV_PROD" ".env.production" +./scripts/common/writeEnvsToFile.sh "$ENV_PROD_E2E" ".env.production.e2e" + +# Use .env.development as the default +cp .env.development .env +echo ".env.development copied to .env" +echo "envs successfully retrieved and saved 🥳"