Changeset View
Changeset View
Standalone View
Standalone View
contrib/source-control-tools/automated-commits.sh
Show All 13 Lines | |||||
Generate a commit from available recipes. | Generate a commit from available recipes. | ||||
The given script may produce a commit. If a commit is generated this way, it will be landed. | The given script may produce a commit. If a commit is generated this way, it will be landed. | ||||
Options: | Options: | ||||
-h, --help Display this help message. | -h, --help Display this help message. | ||||
Environment Variables: | Environment Variables: | ||||
COMMIT_TYPE (required) The commit recipe to run. | |||||
DRY_RUN If set to 'no', this script will push the generated changes upstream. Default: 'yes' | DRY_RUN If set to 'no', this script will push the generated changes upstream. Default: 'yes' | ||||
EOF | EOF | ||||
} | } | ||||
SCRIPT="" | SCRIPT="" | ||||
SCRIPT_ARGS=() | SCRIPT_ARGS=() | ||||
# Parse command line arguments | # Parse command line arguments | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
-h|--help) | -h|--help) | ||||
help_message | help_message | ||||
exit 0 | exit 0 | ||||
;; | ;; | ||||
*) | *) | ||||
SCRIPT="$1" | SCRIPT="$1" | ||||
shift | shift | ||||
SCRIPT_ARGS=("$@") | SCRIPT_ARGS=("$@") | ||||
break | break | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
: "${COMMIT_TYPE:=}" | |||||
if [ -z "${COMMIT_TYPE}" ]; then | |||||
echo "Error: Environment variable COMMIT_TYPE must be set" | |||||
exit 2 | |||||
fi | |||||
LAND_PATCH_ARGS=() | LAND_PATCH_ARGS=() | ||||
case ${DRY_RUN:=yes} in | case ${DRY_RUN:=yes} in | ||||
no|NO|false|FALSE) | no|NO|false|FALSE) | ||||
# Nothing to do | # Nothing to do | ||||
;; | ;; | ||||
*) | *) | ||||
LAND_PATCH_ARGS+=("--dry-run") | LAND_PATCH_ARGS+=("--dry-run") | ||||
;; | ;; | ||||
esac | esac | ||||
OLD_HEAD="$(git rev-parse HEAD)" | OLD_HEAD="$(git rev-parse HEAD)" | ||||
echo "Building automated commit '${COMMIT_TYPE}'..." | echo "Building automated commit using '${SCRIPT}'..." | ||||
BOT_PREFIX="[Automated]" | BOT_PREFIX="[Automated]" | ||||
TOPLEVEL=$(git rev-parse --show-toplevel) | TOPLEVEL=$(git rev-parse --show-toplevel) | ||||
BUILD_DIR="${TOPLEVEL}/abc-ci-builds/automated-commit-${COMMIT_TYPE}" | BUILD_DIR="${TOPLEVEL}/abc-ci-builds/automated-commit-$(basename ${SCRIPT})" | ||||
mkdir -p "${BUILD_DIR}" | mkdir -p "${BUILD_DIR}" | ||||
export BUILD_DIR | export BUILD_DIR | ||||
DEVTOOLS_DIR="${TOPLEVEL}"/contrib/devtools | |||||
# Make sure tree is clean | # Make sure tree is clean | ||||
if [ -n "$(git status --porcelain)" ]; then | if [ -n "$(git status --porcelain)" ]; then | ||||
echo "Error: The source tree has unexpected changes. Clean up any changes (try 'git stash') and try again." | echo "Error: The source tree has unexpected changes. Clean up any changes (try 'git stash') and try again." | ||||
exit 10 | exit 10 | ||||
fi | fi | ||||
case "${COMMIT_TYPE}" in | |||||
archive-release-notes) | |||||
# shellcheck source=../utils/compare-version.sh | |||||
source "${TOPLEVEL}"/contrib/utils/compare-version.sh | |||||
RELEASE_NOTES_FILE="${TOPLEVEL}/doc/release-notes.md" | |||||
RELEASE_NOTES_VERSION=$(sed -n "1s/^Bitcoin ABC version \([0-9]\+\.[0-9]\+\.[0-9]\+\).\+$/\1/p" "${RELEASE_NOTES_FILE}") | |||||
RELEASE_NOTES_ARCHIVE="${TOPLEVEL}/doc/release-notes/release-notes-${RELEASE_NOTES_VERSION}.md" | |||||
CURRENT_VERSION="" | |||||
get_current_version CURRENT_VERSION | |||||
# Compare the versions. We only want to archive the release notes if the | |||||
# current version is greater the our release notes version. | |||||
if version_less_equal "${CURRENT_VERSION}" "${RELEASE_NOTES_VERSION}" | |||||
then | |||||
echo "Current version ${CURRENT_VERSION} <= release-notes version ${RELEASE_NOTES_VERSION}, skip the update" | |||||
exit 0 | |||||
fi | |||||
# Archive the release notes | |||||
cp "${RELEASE_NOTES_FILE}" "${RELEASE_NOTES_ARCHIVE}" | |||||
# Generate a fresh blank release notes file for the new version | |||||
PROJECT_VERSION="${CURRENT_VERSION}" envsubst < "${TOPLEVEL}/doc/release-notes/release-notes.md.in" > "${RELEASE_NOTES_FILE}" | |||||
git add "${RELEASE_NOTES_FILE}" "${RELEASE_NOTES_ARCHIVE}" | |||||
git commit -m "${BOT_PREFIX} Archive release notes for version ${RELEASE_NOTES_VERSION}" | |||||
;; | |||||
*) | |||||
if [ -z "${SCRIPT}" ]; then | |||||
echo "Error: Invalid commit name '${COMMIT_TYPE}'" | |||||
exit 10 | |||||
fi | |||||
if [ ! -f "${SCRIPT}" ]; then | if [ ! -f "${SCRIPT}" ]; then | ||||
echo "Error: '${SCRIPT}' does not exist" | echo "Error: '${SCRIPT}' does not exist" | ||||
exit 10 | exit 10 | ||||
fi | fi | ||||
"${SCRIPT}" "${SCRIPT_ARGS[@]}" | "${SCRIPT}" "${SCRIPT_ARGS[@]}" | ||||
;; | |||||
esac | |||||
# Bail early if there's nothing to land | # Bail early if there's nothing to land | ||||
if [ "$(git rev-parse HEAD)" == "${OLD_HEAD}" ]; then | if [ "$(git rev-parse HEAD)" == "${OLD_HEAD}" ]; then | ||||
echo "No new changes. Nothing to do." | echo "No new changes. Nothing to do." | ||||
exit 0 | exit 0 | ||||
fi | fi | ||||
# Land the generated commit | # Land the generated commit | ||||
"${TOPLEVEL}"/contrib/source-control-tools/land-patch.sh "${LAND_PATCH_ARGS[@]}" | "${TOPLEVEL}"/contrib/source-control-tools/land-patch.sh "${LAND_PATCH_ARGS[@]}" |