blob: 0b4553efdc72f20287088a93c36bebd72c160546 [file] [log] [blame]
#!/bin/bash
#
# This script rebuilds the Buildbucket plugin and runs a local Gerrit
# instance with the Buildbucket plugin.
#
# This assumes that a Gerrit testsite has already been initialized; see
# https://gerrit-review.googlesource.com/Documentation/dev-readme.html for site
# initialization instructions.
#
# Usage: Invoke with no arguments. Set the environment variables GERRIT_DIR and
# GERRIT_TESTSITE if necessary.
set -eu
readonly SCRIPT_DIR=$(realpath "$(dirname "${0}")")
readonly GERRIT_DIR=$(realpath "${GERRIT_DIR:-${SCRIPT_DIR}/../..}")
readonly GERRIT_TESTSITE_DIR=$(realpath \
"${GERRIT_TESTSITE:-${GERRIT_DIR}/../gerrit_testsite}")
echo "Using ${SCRIPT_DIR} as Buildbucket plugin directory."
echo "Using ${GERRIT_DIR} as Gerrit directory."
echo "Using ${GERRIT_TESTSITE_DIR} as Gerrit testsite directory."
# Move to the Gerrit directory so that Bazel can find the workspace.
pushd "${GERRIT_DIR}"
# We want to force re-build even if only static files changed.
rm -f bazel-bin/plugins/buildbucket/buildbucket.jar
bazel build plugins/buildbucket
# Copy the built plugin into the testsite directory. The .jar file in the
# destination directory is set as read-only, so it has to be force-removed.
rm -f "${GERRIT_TESTSITE_DIR}/plugins/buildbucket.jar"
cp bazel-bin/plugins/buildbucket/buildbucket.jar \
"${GERRIT_TESTSITE_DIR}/plugins/buildbucket.jar"
# Gerrrit docs say to use the same Java version that Bazel used for the build.
"$(bazel info output_base)/external/local_jdk/bin/java" \
-jar bazel-bin/gerrit.war daemon -d "${GERRIT_TESTSITE_DIR}" \
--console-log
popd