Skip to content

Commit

Permalink
j
Browse files Browse the repository at this point in the history
  • Loading branch information
atn4z7 committed Feb 23, 2024
1 parent cda69dc commit 31d58ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/bitrise-envs-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/core-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
echo "envs saved to $output_file"
25 changes: 25 additions & 0 deletions packages/core-mobile/scripts/getEnvs.sh
Original file line number Diff line number Diff line change
@@ -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 🥳"

0 comments on commit 31d58ba

Please sign in to comment.