Skip to content

Commit

Permalink
Add check for override-snapshot to check revisions for components fro…
Browse files Browse the repository at this point in the history
…m the same repo aligns
  • Loading branch information
creydr committed Dec 19, 2024
1 parent 9e037ff commit f5c37cc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions hack/generate/override-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ EOF
rm -rf "${tmp_catalog_dir}"
}

function verify_component_snapshot {
local snapshot_file repo revision component repo_revision failed
snapshot_file="${1}/override-snapshot.yaml"
declare -A repo_revision=()

while IFS= read -r json; do
repo="$(echo "$json" | jq -r .source.git.url)"
repo=${repo%".git"} # remove optional .git suffix from repo name
revision="$(echo "$json" | jq -r .source.git.revision)"
component="$(echo "$json" | jq -r .name)"

if [[ ! -v repo_revision[$repo] ]]; then
# no revision for repo so far --> add it to map
repo_revision[$repo]=$revision
else
if [[ "${repo_revision[$repo]}" != "$revision" ]]; then
# revisions don't match
if [[ $component =~ "serverless-bundle" ]]; then
#ignore serverless bundle
continue
fi

echo "Revision for ${component} didn't match. Expected revision ${repo_revision[$repo]} for repo ${repo}, but got ${revision}"
failed="true"
fi
fi

done <<< "$(yq read --tojson "${snapshot_file}" "spec.components[*]")"

if [[ "$failed" == "true" ]]; then
exit 1
fi
}

function create_fbc_snapshots {
local rootdir snapshot_dir so_version
rootdir="$(dirname "$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")")"
Expand Down Expand Up @@ -165,5 +199,6 @@ function print_cves {

target_dir="${1:?Provide a target directory for the override snapshots as arg[1]}"
create_component_snapshot "${target_dir}"
verify_component_snapshot "${target_dir}"
create_fbc_snapshots "${target_dir}"
print_cves "${target_dir}"

0 comments on commit f5c37cc

Please sign in to comment.