Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
atn4z7 committed Feb 21, 2024
1 parent ce44beb commit c38bf58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/bitrise-envs-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ jobs:
contents: read

steps:
- name: Check out repo
uses: actions/checkout@v3

- name: Configure AWS Credentials Action for GitHub Actions
uses: aws-actions/[email protected]
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::975050371175:role/github-sa-role
role-session-name: githubsa
- name: Get secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v1
with:
secret-ids: |
core/dev/mobile/.env.development.test
# - name: Retrieve envs from AWS Secrets Manager
# run: |
# aws secretsmanager get-secret-value --secret-id "core/dev/mobile/.env.development.test"

- name: Retrieve envs from AWS Secrets Manager
working-directory: ./packages/core-mobile/scripts/github
run: |
./fetchEnvsFromAWS.sh "core/dev/mobile/.env.development.test" ".env.test"
cat .env.test
33 changes: 33 additions & 0 deletions packages/core-mobile/scripts/github/fetchEnvsFromAWS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Check if the correct number of parameters are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <secret_id> <output_filename>"
exit 1
fi

# Retrieve the secret value and assign it to the data variable
data=$(sudo aws secretsmanager get-secret-value --secret-id "$1" | grep "SecretString")


# Check if the secret value is empty
if [ -z "$data" ]; then
echo "Error: Failed to retrieve secret value"
exit 1
fi

# Extract the secret string value
data=$(echo "$data" | sed 's/.*"SecretString": "\(.*\)".*/\1/')

# Parse the string to extract key-value pairs
pairs=$(echo "$data" | sed 's/[{}"]//g' | tr ',' '\n' | tr ':' '=')

# Erase the content of the output file
> "$2"

# Write the key-value pairs to the output file
echo "$pairs" | while IFS= read -r line; do
echo "$line" | sed 's/\\//g' >> "$2"
done

echo "envs saved to $2"

0 comments on commit c38bf58

Please sign in to comment.