Skip to content

Commit 71248ea

Browse files
[2024a] [CI] Enhance params env check script (#575)
* let's run params-env workflow also on push Let's run the params-env workflow that checks values in params.env and commit.env files also on push event and also on dispatch_workflow. * 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. * check-params-env.sh prints also time of creation of the checked image --------- Co-authored-by: Jan Stourac <[email protected]>
1 parent 6a1f41e commit 71248ea

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

.github/workflows/params-env.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
22
name: Validation of image references (image SHAs) in params.env and runtime images
33
on: # yamllint disable-line rule:truthy
4+
push:
45
pull_request:
56
paths:
67
- 'manifests/base/commit.env'
78
- 'manifests/base/params.env'
89
- 'ci/check-params-env.sh'
10+
workflow_dispatch:
911

1012
permissions:
1113
contents: read

ci/check-params-env.sh

Lines changed: 31 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
@@ -226,6 +248,7 @@ function check_image() {
226248
local image_name
227249
local image_commit_id
228250
local image_commitref
251+
local image_created
229252

230253
image_metadata="$(skopeo inspect --config "docker://${image_url}")" || {
231254
echo "Couldn't download image metadata with skopeo tool!"
@@ -243,6 +266,10 @@ function check_image() {
243266
echo "Couldn't parse '.config.Labels."io.openshift.build.commit.ref"' from image metadata!"
244267
return 1
245268
}
269+
image_created=$(echo "${image_metadata}" | jq --raw-output '.created') || {
270+
echo "Couldn't parse '.created' from image metadata!"
271+
return 1
272+
}
246273

247274
local config_env
248275
local build_name_raw
@@ -267,6 +294,7 @@ function check_image() {
267294
}
268295

269296
echo "Image name retrieved: '${image_name}'"
297+
echo "Image created: '${image_created}'"
270298

271299
check_image_variable_matches_name_and_commitref "${image_variable}" "${image_name}" "${image_commitref}" "${openshift_build_name}" || return 1
272300

@@ -282,13 +310,13 @@ ret_code=0
282310
echo "Starting check of image references in files: '${COMMIT_ENV_PATH}' and '${PARAMS_ENV_PATH}'"
283311
echo "---------------------------------------------"
284312

285-
check_variables_uniq "${COMMIT_ENV_PATH}" || {
313+
check_variables_uniq "${COMMIT_ENV_PATH}" "true" || {
286314
echo "ERROR: Variable names in the '${COMMIT_ENV_PATH}' file failed validation!"
287315
echo "----------------------------------------------------"
288316
ret_code=1
289317
}
290318

291-
check_variables_uniq "${PARAMS_ENV_PATH}" || {
319+
check_variables_uniq "${PARAMS_ENV_PATH}" "false" || {
292320
echo "ERROR: Variable names in the '${PARAMS_ENV_PATH}' file failed validation!"
293321
echo "----------------------------------------------------"
294322
ret_code=1

ci/check-runtime-images.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function check_image() {
2727
local img_tag
2828
local img_url
2929
local img_metadata
30+
local img_created
3031

3132
img_tag=$(jq -r '.metadata.tags[0]' "${runtime_image_file}") || {
3233
echo "ERROR: Couldn't parse image tags metadata for '${runtime_image_file}' runtime image file!"
@@ -42,13 +43,20 @@ function check_image() {
4243
return 1
4344
}
4445

46+
img_created=$(echo "${img_metadata}" | jq --raw-output '.created') || {
47+
echo "Couldn't parse '.created' from image metadata!"
48+
return 1
49+
}
50+
4551
local expected_string="runtime-${img_tag}-ubi"
4652
echo "Checking that '${expected_string}' is present in the image metadata"
4753
echo "${img_metadata}" | grep --quiet "${expected_string}" || {
4854
echo "ERROR: The string '${expected_string}' isn't present in the image metadata at all. Please check that the referenced image '${img_url}' is the correct one!"
4955
return 1
5056
}
5157

58+
echo "Image created: '${img_created}'"
59+
5260
# TODO: we shall extend this check to check also Label "io.openshift.build.commit.ref" value (e.g. '2024a') or something similar
5361
}
5462

0 commit comments

Comments
 (0)