diff --git a/contrib/bots/land-bot.sh b/contrib/bots/land-bot.sh new file mode 100755 --- /dev/null +++ b/contrib/bots/land-bot.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +# Copyright (c) 2019 The Bitcoin developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C + +set -euxo pipefail + +TOPLEVEL=$(git rev-parse --show-toplevel) +DEFAULT_BUILD_DIR="${TOPLEVEL}/build" + +help_message() { + set +x + echo "Apply a patch from Phabricator, build and test it against the latest master, then land if successful." + echo "" + echo "Options:" + echo "-h, --help Display this help message." + echo "-n, --no-land Run the script, but do not land the change at the end. This is useful for testing." + echo "-r, --revision The Differential revision ID used in Phabricator that you want to land. (ex: D1234)" + echo "" + echo "Environment Variables:" + echo "ABC_BUILD_NAME Default: build-default" + echo "BUILD_DIR Default: ${DEFAULT_BUILD_DIR}" + set -x +} + +: "${ABC_BUILD_NAME:=build-default}" +: "${BUILD_DIR:=${DEFAULT_BUILD_DIR}}" +ARC_LAND_OPTIONS="" +REVISION="" + +# Parse command line arguments +while [[ $# -gt 0 ]]; do +case $1 in + -h|--help) + help_message + exit 0 + shift # shift past argument + ;; + -n|--no-land) + ARC_LAND_OPTIONS="--hold" + shift # shift past argument + ;; + -r|--revision) + REVISION="$2" + shift # shift past argument + shift # shift past value + ;; + *) + echo "Unknown argument: $1" + help_message + exit 1 + shift # shift past argument + ;; +esac +done + +if [ -z "$REVISION" ]; then + echo "Error: -r, --revision was not set." + help_message + exit 10 +fi + +# Cleanup the repo whether the script succeeded for failed +cleanup() { + git checkout master + git branch -D "arcpatch-${REVISION}" || true +} +trap "cleanup" EXIT + +# Sanity operations so that we can test this script locally. +# Under normal operation, checking out master isn't necessary. +git checkout master +git pull --verbose --ff-only origin master + +# Note: `: | arc ...` pipes an empty string to stdin incase arcanist prompts +# for user input. This fails and is treated as an error. +: | arc patch "$REVISION" --skip-dependencies + +git rebase master + +# Cleanup the build dir if it already exists +rm -rf "${BUILD_DIR}" + +export ABC_BUILD_NAME +export BUILD_DIR +"${TOPLEVEL}/contrib/teamcity/build-configurations.sh" + +read -a ARC_LAND_PARAMS <<< "--revision $REVISION $ARC_LAND_OPTIONS" +: | arc land "${ARC_LAND_PARAMS[@]}"