Skip to content

Commit

Permalink
JBIDE-21145 add support for checking ALL the SHAs in a buildinfo.json…
Browse files Browse the repository at this point in the history
… file, so we can diff these to compare aggregate builds
  • Loading branch information
nickboldt committed Dec 1, 2015
1 parent 3734dce commit cab99f1
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions util/checkLatestPublishedSHA.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
tmpdir=`mktemp -d`
mkdir -p $tmpdir

# by default we only want the top-most SHA, but for aggregate builds we can compare ALL the SHAs for a more accurate picture
compareAllSHAs=0
debug=0

usage ()
{
echo "Usage : $0 -s source_path/to/buildinfo.json -t target_path/to/buildinfo.json"
Expand All @@ -27,6 +31,8 @@ while [[ "$#" -gt 0 ]]; do
case $1 in
'-s') SOURCE_PATH="$2"; SOURCE_PATH=${SOURCE_PATH%/}; shift 1;; # ${WORKSPACE}/sources/site/target/repository [trim trailing slash]
'-t') TARGET_PATH="$2"; TARGET_PATH=${TARGET_PATH%/}; shift 1;; # neon/snapshots/builds/<job-name>/<build-number> [trim trailing slash]
'-all') compareAllSHAs="1"; shift 0;;
'-debug') debug="$2"; shift 1;;
esac
shift 1
done
Expand Down Expand Up @@ -55,12 +61,16 @@ getSHA ()
{
getSHAReturn=""
if [[ "$1" ]] && [[ -f "$1" ]]; then
if [[ ${compareAllSHAs} == 0 ]]; then # compare one SHA
# {
# "timestamp" : 1425345819988,
# "revision" : {
# "HEAD" : "79b3dcd80d3c6f96b3671f5eae6f25d94d5c3801",
# "currentBranch" : "HEAD",
getSHAReturn=$(head -5 "$1" | grep -A1 "revision" | grep -v "revision" | sed -e "s#.\+: \"\(.\+\)\".\+#\1#") # 79b3dcd80d3c6f96b3671f5eae6f25d94d5c3801
else # compare ALL SHAs
getSHAReturn="$(cat "$1" | grep -A1 "revision" | grep -v "revision" | sed -e "s#.\+: \"\(.\+\)\".\+#\1#" | grep -v -- "--" | sort)"
fi
fi
}

Expand All @@ -78,13 +88,39 @@ fi
SHA1=""; getSHA "${json}"; if [[ ${getSHAReturn} ]]; then SHA1="${getSHAReturn}"; fi
SHA2=""; getSHA "${SOURCE_PATH}"; if [[ ${getSHAReturn} ]]; then SHA2="${getSHAReturn}"; fi

if [[ ${compareAllSHAs} == 1 ]]; then # compare multiple SHAs, but filter out the lines that are the same so we're only comparing the differences
for SH in $SHA1; do echo $SH >> $tmpdir/SHA1; done
for SH in $SHA2; do echo $SH >> $tmpdir/SHA2; done
SHA1uniq=$(grep -v -x -f $tmpdir/SHA2 $tmpdir/SHA1)
SHA2uniq=$(grep -v -x -f $tmpdir/SHA1 $tmpdir/SHA2)
fi

# purge temp folder
rm -fr ${tmpdir}

if [[ "${SHA1}" ]] && [[ "${SHA2}" ]] && [[ "${SHA1}" == "${SHA2}" ]]; then # SHAs match - return false
# echo "[INFO] SHAs match: ${SHA1} == ${SHA2}"
if [[ $debug != 0 ]]; then
echo "[INFO] SHAs match:
${SHA1} (target = ${TARGET_PATH})
==
${SHA2} (source = ${SOURCE_PATH})"
fi
echo "false"
else # SHAs are different (or one is null because no previous SHA) - return true
# echo "[INFO] SHAs differ: ${SHA1} != ${SHA2}"
if [[ $debug != 0 ]]; then
if [[ ${compareAllSHAs} == 1 ]]; then
echo "[INFO] SHAs differ:"
echo "${SHA1}" | egrep "${SHA1uniq}"
echo " (target = ${TARGET_PATH})"
echo " !="
echo "${SHA2}" | egrep "${SHA2uniq}"
echo " (source = ${SOURCE_PATH})"
else
echo "[INFO] SHAs differ:
${SHA1} (target = ${TARGET_PATH})
!=
${SHA2} (source = ${SOURCE_PATH})"
fi
fi
echo "true"
fi

0 comments on commit cab99f1

Please sign in to comment.