Skip to content

Commit

Permalink
feat: compare setters key function (#34)
Browse files Browse the repository at this point in the history
* add setters compare function

* fix comments spacing

* fix bash linting error

* fix bash linting error

* remove unused echo

* remove unecessary error checking
  • Loading branch information
lucstjean-ssc authored May 11, 2023
1 parent 3e2827a commit f23c1a1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/kpt/hydrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,29 @@ hydrate_env () {
print_error "Missing customization: ${SOURCE_CUSTOMIZATION_DIR}/${environment}/${setters_file}"
error_counter=$((error_counter+1))
status_validate_setters["${dir_id}"]=1

# check if there are any missing keys between the source base and source customizations setters files
else
# Create temp dir for comparing of keys
mkdir -p "${env_temp_subdir}/compare-keys"
echo "${SOURCE_BASE_DIR}/${setters_file}"
echo "${SOURCE_CUSTOMIZATION_DIR}/${environment}/${setters_file}"
# Fetch keys in first setters file
yq eval '.data | sort_keys(.) | keys' "${SOURCE_BASE_DIR}/${setters_file}" | yq '... comments=""' > "${env_temp_subdir}/compare-keys/source_base_setters.yaml"
# Fetch keys in second setters file
yq eval '.data | sort_keys(.) | keys' "${SOURCE_CUSTOMIZATION_DIR}/${environment}/${setters_file}" | yq '... comments=""' > "${env_temp_subdir}/compare-keys/source_customization_setters.yaml"
# compare keys between source-base and source-customization setters files
result=$(comm -3 --nocheck-order "${env_temp_subdir}/compare-keys/source_base_setters.yaml" "${env_temp_subdir}/compare-keys/source_customization_setters.yaml")
# Check if there were any differences
if [ -n "$result" ]; then
print_error "Missing key(s) detected. The following keys are missing."
echo -e "$result\n"
error_counter=$((error_counter+1))
status_validate_setters["${dir_id}"]=1
else
echo -e "No missing key(s) detected\n"
fi
fi
# TODO: possible enhancement, maybe check if there is a diff?
done
# exit function if errors were found
if [[ "${status_validate_setters[${dir_id}]}" -ne 0 ]] ; then
Expand Down

0 comments on commit f23c1a1

Please sign in to comment.