#!/bin/sh
#
# bazel_precheck.sh | Run pre-test checks and commands
#
# Ensure that bazel does not take up too many resources by:
# 1. running the setup script to use the correct version of bazel
# 2. shutting down bazel
# 3. removing the bazel cache
#
# @copyright Highly Confidential and Proprietary Zoox Information. Copyright (c) Zoox
#

# 0.
# Ensure script is not being run as root by checking the effective user ID against that of root user
if [ "$(id -u)" -eq 0 ]; then
    echo "Do not use sudo when running this script/test"
    exit 1
fi

# 1.
# Run the setup script for dev with --no-ask-pass to bypass sudo prompt
# and tags for bazel upgrade / downgrade
scripts/setup/setup.sh dev --no-ask-pass --tags bazel

# 2.
bazel clean --expunge

# 3.
rm -rf ~/.cache/bazel
