sourcegraph/dev/ci/scripts/compare-hash.sh
Erik Seliger 58fe87f6b5
enterprise: Move last directory out (#57392)
This is the end of the PR train to remove the enterprise directory from out repo since we have consolidated to use a single license.

Bye rough code split :)
2023-10-05 20:15:40 +00:00

56 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# This script exits 0 if the hash script output has changed against the previous revision,
# indicating a new build should be created. If nothing has changed, a special exit code
# 222 is returned.
HASH_SCRIPT=$1
set -ex -o pipefail
current_commit=$(git rev-parse HEAD)
checkout() {
git checkout -f "$1"
# Re-run asdf to ensure we have the correct set of utilities to
# run the currently checked out version of the Go unit tests.
echo "--- asdf install checked out tools"
./dev/ci/asdf-install.sh
}
restore() {
checked_out_commit=$(git rev-parse HEAD)
if [ "$current_commit" != "$checked_out_commit" ]; then
echo "Restoring correct commit"
checkout -
else
echo "Already on correct commit"
fi
}
trap restore EXIT
# Build previous
checkout HEAD^
commit=$(git rev-parse HEAD)
echo "--- compare-hash.sh: running $HASH_SCRIPT against $commit"
if test -f "$HASH_SCRIPT"; then
previous_hash=$($HASH_SCRIPT)
else
echo "+++ Previous revision does not have a hash script at $HASH_SCRIPT"
exit 0
fi
# Build current
checkout -
echo "--- compare-hash.sh: running $HASH_SCRIPT against $current_commit"
new_hash=$($HASH_SCRIPT)
if [ "$new_hash" == "$previous_hash" ]; then
echo "+++ new_hash and previous_hash match - nothing has changed, exiting 222 soft fail"
exit 222
else
echo "+++ new_hash and previous_hash mismatch: '$new_hash' and '$previous_hash' respectively"
echo 0
fi