Changeset View
Changeset View
Standalone View
Standalone View
contrib/source-control-tools/land-patch.sh
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if [ -n "${REVISION}" ] && [ -z "${CONDUIT_TOKEN}" ]; then | ||||
exit 10 | exit 10 | ||||
fi | fi | ||||
set -x | set -x | ||||
if [ -n "${REVISION}" ]; then | if [ -n "${REVISION}" ]; then | ||||
# Temporarily stop verbose logging to prevent leaking CONDUIT_TOKEN | # Temporarily stop verbose logging to prevent leaking CONDUIT_TOKEN | ||||
set +x | set +x | ||||
# Fetch the revision and check its review status | # Fetch the revision and check its review status | ||||
REVIEW_STATUS=$(curl "https://reviews.bitcoinabc.org/api/differential.revision.search" \ | REVISION_RESULT=$(curl "https://reviews.bitcoinabc.org/api/differential.revision.search" \ | ||||
-d "api.token=${CONDUIT_TOKEN}" \ | -d "api.token=${CONDUIT_TOKEN}" \ | ||||
-d "constraints[ids][0]=${REVISION:1}" |\ | -d "constraints[ids][0]=${REVISION:1}") || { | ||||
jq '.result.data[].fields.status.value') || { | echo "Error: Failed to fetch revision '${REVISION}'" | ||||
echo "curl output:" | |||||
echo "${REVISION_RESULT}" | |||||
exit 20 | |||||
} | |||||
set -x | |||||
ERROR_INFO=$(echo "${REVISION_RESULT}" | jq '.error_info') | |||||
if [ "${ERROR_INFO}" != "null" ]; then | |||||
echo "Conduit error while fetching '${REVISION}': ${ERROR_INFO}" | |||||
exit 21 | |||||
fi | |||||
REVIEW_STATUS=$(echo "${REVISION_RESULT}" | jq '.result.data[].fields.status.value') || { | |||||
echo "Error: Failed to fetch review status of revision '${REVISION}'" | echo "Error: Failed to fetch review status of revision '${REVISION}'" | ||||
echo "The 'status' fields may be missing or malformed." | echo "The 'status' fields may be missing or malformed." | ||||
exit 30 | exit 22 | ||||
} | } | ||||
set -x | |||||
# We only trust code that has been accepted | # We only trust code that has been accepted | ||||
if [ "${REVIEW_STATUS}" != "\"accepted\"" ]; then | if [ "${REVIEW_STATUS}" != "\"accepted\"" ]; then | ||||
echo "Error: Revision '${REVISION}' has not been accepted" | echo "Error: Revision '${REVISION}' has not been accepted" | ||||
exit 31 | exit 23 | ||||
fi | fi | ||||
fi | fi | ||||
# IMPORTANT NOTE: The patch is trusted past this point. It was either reviewed | # IMPORTANT NOTE: The patch is trusted past this point. It was either reviewed | ||||
# and accepted or it was auto-generated. | # and accepted or it was auto-generated. | ||||
TOPLEVEL=$(git rev-parse --show-toplevel) | TOPLEVEL=$(git rev-parse --show-toplevel) | ||||
DEVTOOLS_DIR="${TOPLEVEL}"/contrib/devtools | DEVTOOLS_DIR="${TOPLEVEL}"/contrib/devtools | ||||
BUILD_DIR="${TOPLEVEL}"/build | BUILD_DIR="${TOPLEVEL}"/build | ||||
mkdir -p "${BUILD_DIR}" | mkdir -p "${BUILD_DIR}" | ||||
export BUILD_DIR | export BUILD_DIR | ||||
# Applying brace expansion ensures the remainder of this script is loaded into memory, | # Applying brace expansion ensures the remainder of this script is loaded into memory, | ||||
# as most versions of bash typically load scripts in chunks as they run. For patches | # as most versions of bash typically load scripts in chunks as they run. For patches | ||||
# that alter this script, this prevents those changes from affecting the remainder of | # that alter this script, this prevents those changes from affecting the remainder of | ||||
# the execution. | # the execution. | ||||
{ | { | ||||
if [ -n "${REVISION}" ]; then | if [ -n "${REVISION}" ]; then | ||||
# Pull the patch from Phabricator and rebase it on latest master | # Pull the patch from Phabricator and rebase it on latest master | ||||
"${TOPLEVEL}"/contrib/source-control-tools/autopatch.sh --revision "${REVISION}" | "${TOPLEVEL}"/contrib/source-control-tools/autopatch.sh --revision "${REVISION}" | ||||
else | else | ||||
# TODO: This will primarily be for scheduled, automated commits. | # TODO: This will primarily be for scheduled, automated commits. | ||||
echo "Error: Landing unreviewed patches is not supported yet." | echo "Error: Landing unreviewed patches is not supported yet." | ||||
exit 20 | exit 30 | ||||
fi | fi | ||||
# TODO: Autogen (such as manpages, updating timings.json, copyright header, etc.) | # TODO: Autogen (such as manpages, updating timings.json, copyright header, etc.) | ||||
# Sanity checks | # Sanity checks | ||||
"${DEVTOOLS_DIR}"/smoke-tests.sh | "${DEVTOOLS_DIR}"/smoke-tests.sh | ||||
if [ -n "${REVISION}" ]; then | if [ -n "${REVISION}" ]; then | ||||
echo "Landing revision '${REVISION}' with arcanist arguments: ${ARC_LAND_ARGS[*]}" | echo "Landing revision '${REVISION}' with arcanist arguments: ${ARC_LAND_ARGS[*]}" | ||||
# Stop logging verbosely to prevent leaking CONDUIT_TOKEN | # Stop logging verbosely to prevent leaking CONDUIT_TOKEN | ||||
set +x | set +x | ||||
# Land a commit using arcanist. This ensures the diff is reviewed and closed properly. | # Land a commit using arcanist. This ensures the diff is reviewed and closed properly. | ||||
: | arc land "${ARC_LAND_ARGS[@]}" --revision "${REVISION}" --conduit-token "${CONDUIT_TOKEN}" | : | arc land "${ARC_LAND_ARGS[@]}" --revision "${REVISION}" --conduit-token "${CONDUIT_TOKEN}" | ||||
set -x | set -x | ||||
else | else | ||||
# TODO: Push a git commit directly. This will primarily be for scheduled, automated commits. | # TODO: Push a git commit directly. This will primarily be for scheduled, automated commits. | ||||
echo "Error: Pushing unreviewed patches is not supported yet." | echo "Error: Pushing unreviewed patches is not supported yet." | ||||
exit 30 | exit 31 | ||||
fi | fi | ||||
# This MUST be the last line to ensure no changes to this script on-disk can affect the execution | # This MUST be the last line to ensure no changes to this script on-disk can affect the execution | ||||
# that is running right now. See note above for more details. | # that is running right now. See note above for more details. | ||||
exit 0 | exit 0 | ||||
} | } |