Skip to content

Instantly share code, notes, and snippets.

@EgzonArifi
Created May 13, 2023 12:03
Show Gist options
  • Save EgzonArifi/61c35a7416b66b554e2a51a246f05d28 to your computer and use it in GitHub Desktop.
Save EgzonArifi/61c35a7416b66b554e2a51a246f05d28 to your computer and use it in GitHub Desktop.
Update .xcconfig from environment variables in CI
#!/bin/bash
set -e
CONFIG_FILE="$1"
if [ -z "$CONFIG_FILE" ]; then
echo "Error: Missing required argument."
exit 1
fi
# Define arrays for keys and values
KEYS=("API_KEY" "PUSHER_SECRET" "SDK_LICENSE_KEY")
VALUES=("${API_KEY}" "${SDK_LICENSE_KEY}")
# Verify the length of the arrays
if [ ${#KEYS[@]} -ne ${#VALUES[@]} ]; then
echo "Error: Mismatch in the number of keys and values."
exit 1
fi
# Iterate through the keys and replace the placeholders in the .xcconfig file
for i in "${!KEYS[@]}"; do
key="${KEYS[$i]}"
value="${VALUES[$i]}"
if [ -z "$value" ]; then
echo "Error: Missing value for environment variable $key"
exit 1
fi
sed -i '' "s/${key}_PLACEHOLDER/${value}/g" "${CONFIG_FILE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment