From 7a946a0603263c1f1348aa0fa96f760f1aa2b32b Mon Sep 17 00:00:00 2001 From: Saipriya-1144 Date: Sat, 24 Aug 2024 22:36:24 +0530 Subject: [PATCH] modified update_constants.sh --- monitor_version_scripts/update_constants.sh | 89 +++++++-------------- 1 file changed, 30 insertions(+), 59 deletions(-) diff --git a/monitor_version_scripts/update_constants.sh b/monitor_version_scripts/update_constants.sh index 2b70a3b9a..751e46cbc 100644 --- a/monitor_version_scripts/update_constants.sh +++ b/monitor_version_scripts/update_constants.sh @@ -13,73 +13,44 @@ cat < $constants_FILE variables: EOL -while IFS= read -r line; do - # Use yq to parse the YAML line and extract the key and value - key=$(echo "$line" | yq e 'keys' - | sed 's/^[[:space:]]*-*//' | sed 's/^[[:space:]]*//') +update_constants_file() { + while IFS= read -r line; do + # Use yq to parse the YAML line and extract the key and value + key=$(echo "$line" | yq e 'keys' - | sed 's/^[[:space:]]*-*//' | sed 's/^[[:space:]]*//') - value=$(echo "$line" | yq e '.[]' -) + value=$(echo "$line" | yq e '.[]' -) - echo "Key: $key, Value: $value," + echo "Key: $key, Value: $value," - keyInVariableGroup=$(echo "$key" | tr '[:lower:]' '[:upper:]') + keyInVariableGroup=$(echo "$key" | tr '[:lower:]' '[:upper:]') - # Check if the key exists in the environment variables - if printenv "$keyInVariableGroup" > /dev/null; then - # If the key exists, get its value - valueInVariableGroup=$(printenv "$keyInVariableGroup") - echo "The value of $key is: $valueInVariableGroup" + # Check if the key exists in the environment variables + if printenv "$keyInVariableGroup" > /dev/null; then + # If the key exists, get its value + valueInVariableGroup=$(printenv "$keyInVariableGroup") + echo "The value of $key is: $valueInVariableGroup" - if [ "$valueInVariableGroup" = "latest" ]; then - yq eval ".variables.$key = \"$value\"" -i $constants_FILE - echo "Updated constants.yml with latest value $key=$value" - elif [ "$valueInVariableGroup" = "dont_change" ]; then - old_value = $(yq eval ".$key" $Temp_constants_FILE) + if [ "$valueInVariableGroup" = "latest" ]; then + yq eval ".variables.$key = \"$value\"" -i $constants_FILE + echo "Updated constants.yml with latest value $key=$value" + elif [ "$valueInVariableGroup" = "dont_change" ]; then + old_value=$(yq eval ".variables.$key" $Temp_constants_FILE) + yq eval ".variables.$key = \"$old_value\"" -i $constants_FILE + echo "constants.yml with old value $key=$old_value" + else + yq eval ".variables.$key = \"$valueInVariableGroup\"" -i $constants_FILE + echo "Updated constants.yml with given value $key=$valueInVariableGroup" + fi + + else + old_value=$(yq eval ".variables.$key" $Temp_constants_FILE) yq eval ".variables.$key = \"$old_value\"" -i $constants_FILE echo "constants.yml with old value $key=$old_value" - else - yq eval ".variables.$key = \"$valueInVariableGroup\"" -i $constants_FILE - echo "Updated constants.yml with given value $key=$valueInVariableGroup" fi - else - yq eval ".variables.$key = \"$value\"" -i $constants_FILE - echo "Added $key = $value in constants.yml" - fi + done < <(yq e '.[]' "$1") +} -done < <(yq e '.[]' "override_constants.yaml") - -while IFS= read -r line; do - # Use yq to parse the YAML line and extract the key and value - key=$(echo "$line" | yq e 'keys' - | sed 's/^[[:space:]]*-*//' | sed 's/^[[:space:]]*//') - value=$(echo "$line" | yq e '.[]' -) - - echo "Key: $key, Value: $value," - - keyInVariableGroup=$(echo "$key" | tr '[:lower:]' '[:upper:]') - - # Check if the key exists in the environment variables - if printenv "$keyInVariableGroup" > /dev/null; then - # If the key exists, get its value - valueInVariableGroup=$(printenv "$keyInVariableGroup") - echo "The value of $key is: $valueInVariableGroup" - - if [ "$valueInVariableGroup" = "latest" ]; then - yq eval ".variables.$key = \"$value\"" -i $constants_FILE - echo "Updated constants.yml with latest value $key=$value" - elif [ "$valueInVariableGroup" = "dont_change" ]; then - old_value=$(yq eval ".$key" $Temp_constants_FILE) - yq eval ".variables.$key = \"$old_value\"" -i $constants_FILE - echo "constants.yml with old value $key=$old_value" - else - yq eval ".variables.$key = \"$valueInVariableGroup\"" -i $constants_FILE - echo "Updated constants.yml with given value $key=$valueInVariableGroup" - fi - - else - yq eval ".variables.$key = \"$value\"" -i $constants_FILE - echo "Added $key = $value in constants.yml" - fi - - -done < <(yq e '.[]' "latest_stack_versions.yaml") +update_constants_file "override_constants.yaml" +update_constants_file "latest_stack_versions.yaml"