#!/bin/bash
#
#   Sapphire pre-flight checklist.
#   Make sure everything builds and unit tests pass
#   before pushing to the GitHub repo.
#
./verify_clean || exit 1
./prebuild || exit 1

RETRY_SECONDS=5
for attempt in $(seq 1 3); do
    if python3 rack-manifest-validator.py ../.. -p sapphire; then
        break
    else
        if [[ $attempt < 3 ]]; then
            echo "Retrying in ${RETRY_SECONDS} seconds..."
            sleep ${RETRY_SECONDS}
        else
            echo "Exhausted retries."
            exit 1
        fi
    fi
done

./verify_clean || exit 1
cd ..
make || exit 1
cd util
./runtests || exit 1
./verify_clean || exit 1
git push || exit 1
exit 0
