Skip to content

Commit b38759a

Browse files
authored
Merge pull request #1021 from atheo89/follow-up-commit
Follow up to update the commit file properly based on image change
2 parents 36f11c6 + 1244b2f commit b38759a

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

ci/sha-digest-updater.sh

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ USER_HASH=$1
44
REPO_OWNER=$2
55
BRANCH=$3
66
REPO_NAME=$4
7-
87
REPO_ROOT=$(git rev-parse --show-toplevel)
8+
99
# Declare and initialize the image skipping log file (This does not commit)
1010
export SKIPPED_LOG="$REPO_ROOT/skipped-images.txt"
1111

@@ -34,20 +34,16 @@ fetch_latest_hash() {
3434
fi
3535
}
3636

37-
# Updates the commits in commit.env
38-
update_commits() {
39-
local REPO_ROOT="$1"
40-
local HASH="$2"
41-
local COMMIT_ENV_PATH="$REPO_ROOT/manifests/base/commit.env"
42-
43-
# Get the complete list of commits N-version to update
44-
local COMMITS
45-
COMMITS=$(grep "\-n=" "$COMMIT_ENV_PATH" | cut -d "=" -f 1)
37+
# Updates a corresponding image commit in commit.env
38+
update_image_commit() {
39+
local image_name="$1"
40+
local hash="$2"
41+
local commit_env_path="$REPO_ROOT/manifests/base/commit.env"
4642

47-
for val in $COMMITS; do
48-
echo "Updating commit '${val}' to $HASH"
49-
sed -i "s|${val}=.*|${val}=${HASH}|" "$COMMIT_ENV_PATH"
50-
done
43+
# Convert image name to match with commit variable name
44+
commit_var=$(echo "$image_name" | sed 's/-n$/-commit-n/')
45+
echo "Updating commit '${commit_var}' to $hash"
46+
sed -i "s|^${commit_var}=.*|${commit_var}=${hash}|" "$commit_env_path"
5147
}
5248

5349
# Function to process runtime images
@@ -150,10 +146,8 @@ if [[ "$REPO_OWNER" == "opendatahub-io" ]]; then
150146
log_skipped_image "$image"
151147
continue
152148
fi
153-
154149
# use `--no-tags` for skopeo once available in newer version
155150
digest=$(skopeo inspect --retry-times 3 "docker://${registry}:${latest_tag}" | jq .Digest | tr -d '"')
156-
157151
# Check for digest validity
158152
if [[ -z "$digest" || "$digest" == "null" ]]; then
159153
echo "Failed to get digest for $latest_tag. Skipping."
@@ -164,9 +158,8 @@ if [[ "$REPO_OWNER" == "opendatahub-io" ]]; then
164158
output="${registry}@${digest}"
165159
echo "NEW: ${output}"
166160
sed -i "s|${image}=.*|${image}=${output}|" "${PARAMS_ENV_PATH}"
161+
update_image_commit "$image" "$HASH"
167162
done
168-
169-
update_commits "$REPO_ROOT" "$HASH"
170163
update_runtime_images
171164

172165
# In case the digest updater function is triggered downstream.
@@ -205,9 +198,7 @@ elif [[ "$REPO_OWNER" == "red-hat-data-services" ]]; then
205198
log_skipped_image "$image"
206199
continue
207200
fi
208-
209201
digest=$(skopeo inspect --retry-times 3 "docker://${registry}:${latest_tag}" | jq .Digest | tr -d '"')
210-
211202
# Check for digest validity
212203
if [[ -z "$digest" || "$digest" == "null" ]]; then
213204
echo "Failed to get digest for $latest_tag. Skipping."
@@ -218,10 +209,9 @@ elif [[ "$REPO_OWNER" == "red-hat-data-services" ]]; then
218209
output="${registry}@${digest}"
219210
echo "NEW: ${output}"
220211
sed -i "s|${image}=.*|${image}=${output}|" "${PARAMS_ENV_PATH}"
212+
update_image_commit "$image" "$HASH"
221213
i=$((i+1))
222214
done
223-
224-
update_commits "$REPO_ROOT" "$HASH"
225215
update_runtime_images
226216

227217
else

0 commit comments

Comments
 (0)