11#! /bin/bash
22
3- # Copyright 2024 Hewlett Packard Enterprise Development LP
3+ # Copyright 2024-2026 Hewlett Packard Enterprise Development LP
44# Other additional copyright holders may be indicated within.
55#
66# The entirety of this work is licensed under the Apache License,
@@ -39,22 +39,32 @@ msg(){
3939NNF_URL=" git@github.com:NearNodeFlash/nnf-deploy.git"
4040
4141WORKSPACE=" workingspace"
42+ DISPLAY_DIFF=false
43+ IMAGES_ONLY=false
4244
4345usage () {
4446 echo " Usage: $PROG [-h]"
45- echo " $PROG [-w workspace_dir] [-u nnf_deploy_url] <VERSION1> <VERSION2>"
47+ echo " $PROG [-d] [-i] [- w workspace_dir] [-u nnf_deploy_url] <VERSION1> <VERSION2>"
4648 echo
4749 echo " VERSION1 Starting version for comparison. This may be"
4850 echo " a tag such as 'v0.1.7'."
4951 echo " VERSION2 Ending version for comparison. This may be"
5052 echo " a tag such as 'v0.1.8'."
53+ echo " -d Display the full diff output."
54+ echo " -i Display only image version changes."
5155 echo " -w workspace_dir Name for working directory. Default: '$WORKSPACE '"
5256 echo " -u nnf_deploy_url URL to the nnf-deploy repo. Default: '$NNF_URL '"
5357 echo
5458}
5559
56- while getopts " hw :u:" opt; do
60+ while getopts " dhiw :u:" opt; do
5761 case $opt in
62+ d)
63+ DISPLAY_DIFF=true
64+ ;;
65+ i)
66+ IMAGES_ONLY=true
67+ ;;
5868 u)
5969 NNF_URL=" $OPTARG "
6070 ;;
@@ -106,7 +116,7 @@ prep_for_manifest() {
106116 rm -rf " $ver "
107117 fi
108118
109- if ! gh release view " $ver " > /dev/null 2>&1 ; then
119+ if ! gh release view -R " $NNF_URL " " $ver " > /dev/null 2>&1 ; then
110120 do_fail " Release $ver does not exist"
111121 fi
112122}
@@ -116,10 +126,14 @@ fetch_and_unpack_manifest() {
116126 local vtar=" $2 "
117127
118128 gh release download -R " $NNF_URL " -O " $vtar " -p manifests.tar " $ver " || do_fail " Unable to find manifests.tar for $ver "
129+ [[ -s " $vtar " ]] || do_fail " Downloaded tarball $vtar is empty"
119130
120131 mkdir " $ver " || do_fail " Cannot mkdir $ver "
121132 cd " $ver "
122133 tar xfo " ../$vtar " || do_fail " Unable to extract tar $vtar "
134+ local count
135+ count=$( find . -type f | wc -l)
136+ [[ $count -gt 0 ]] || do_fail " No files were extracted from $vtar "
123137 cd ..
124138}
125139
@@ -135,6 +149,32 @@ manifest "$ver1" "$v1tar"
135149manifest " $ver2 " " $v2tar "
136150
137151diff_file=" manifest-$ver1 -to-$ver2 .diff"
138- diff -uNr " $ver1 " " $ver2 " > " $diff_file " || echo
139- msg " Manifest diffs for $ver1 to $ver2 are in $WORKSPACE /$diff_file "
152+ rc=0
153+ diff -uNr " $ver1 " " $ver2 " > " $diff_file " || rc=$?
154+ if [[ $rc -eq 0 ]]; then
155+ msg " No differences found between $ver1 and $ver2 "
156+ rm -f " $diff_file "
157+ elif [[ $rc -eq 1 ]]; then
158+ lines=$( wc -l < " $diff_file " | tr -d ' ' )
159+ changed_files=" "
160+ changed_files=$( diff -rq " $ver1 " " $ver2 " ) || true
161+ changed=$( echo " $changed_files " | wc -l | tr -d ' ' )
162+ msg " Manifest diffs for $ver1 to $ver2 are in $WORKSPACE /$diff_file ($lines lines, $changed files changed)"
163+ msg " Changed files:"
164+ echo " $changed_files "
165+
166+ if [[ $IMAGES_ONLY == true ]]; then
167+ msg " "
168+ msg " Image version changes:"
169+ grep -E ' ^[+-].*image:.*:' " $diff_file " | grep -v ' ^[+-][+-][+-]' || echo " (no image changes found)"
170+ fi
171+
172+ if [[ $DISPLAY_DIFF == true ]]; then
173+ msg " "
174+ msg " Full diff:"
175+ cat " $diff_file "
176+ fi
177+ else
178+ do_fail " diff encountered an error (rc=$rc ) comparing $ver1 and $ver2 "
179+ fi
140180
0 commit comments