Skip to content

Commit 7983f1a

Browse files
committed
[CI] enhance the check-params-env.sh to also check uniqueness of values
Up to now, it only checked that variables used in params.env file are unique. This change checks also that the images referenced are unique as we don't expect any of the given variables to hold the same reference.
1 parent 23fb67c commit 7983f1a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

ci/check-params-env.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ EXPECTED_NUM_RECORDS=20
3131

3232
function check_variables_uniq() {
3333
local env_file_path="${1}"
34+
local allow_value_duplicity="${2:=false}"
3435
local ret_code=0
3536

3637
echo "Checking that all variables in the file '${env_file_path}' are unique and expected"
@@ -45,10 +46,31 @@ function check_variables_uniq() {
4546
num_uniq_records=$(echo "${content}" | uniq | wc -l)
4647

4748
test "${num_records}" -eq "${num_uniq_records}" || {
48-
echo "Some of the records in the file aren't unique!"
49+
echo "Some of the variables in the file aren't unique!"
4950
ret_code=1
5051
}
5152

53+
# ----
54+
if test "${allow_value_duplicity}" = "false"; then
55+
echo "Checking that all values assigned to variables in the file '${env_file_path}' are unique and expected"
56+
57+
content=$(sed 's#.*=\(.*\)#\1#' "${env_file_path}" | sort)
58+
59+
local num_values
60+
num_values=$(echo "${content}" | wc -l)
61+
62+
local num_uniq_values
63+
num_uniq_values=$(echo "${content}" | uniq | wc -l)
64+
65+
test "${num_values}" -eq "${num_uniq_values}" || {
66+
echo "Some of the values in the file aren't unique!"
67+
ret_code=1
68+
}
69+
fi
70+
71+
# ----
72+
echo "Checking that there are expected number of records in the file '${env_file_path}'"
73+
5274
test "${num_records}" -eq "${EXPECTED_NUM_RECORDS}" || {
5375
echo "Number of records in the file is incorrect - expected '${EXPECTED_NUM_RECORDS}' but got '${num_records}'!"
5476
ret_code=1
@@ -282,13 +304,13 @@ ret_code=0
282304
echo "Starting check of image references in files: '${COMMIT_ENV_PATH}' and '${PARAMS_ENV_PATH}'"
283305
echo "---------------------------------------------"
284306

285-
check_variables_uniq "${COMMIT_ENV_PATH}" || {
307+
check_variables_uniq "${COMMIT_ENV_PATH}" "true" || {
286308
echo "ERROR: Variable names in the '${COMMIT_ENV_PATH}' file failed validation!"
287309
echo "----------------------------------------------------"
288310
ret_code=1
289311
}
290312

291-
check_variables_uniq "${PARAMS_ENV_PATH}" || {
313+
check_variables_uniq "${PARAMS_ENV_PATH}" "false" || {
292314
echo "ERROR: Variable names in the '${PARAMS_ENV_PATH}' file failed validation!"
293315
echo "----------------------------------------------------"
294316
ret_code=1

0 commit comments

Comments
 (0)