Changeset View
Changeset View
Standalone View
Standalone View
contrib/source-control-tools/automated-commits.sh
#!/usr/bin/env bash | #!/usr/bin/env bash | ||||
# Note: Any bot running this script must have the appropriate permissions to | |||||
# push commits upstream. When running locally, this script will git push in a | |||||
# dry run by default. | |||||
export LC_ALL=C.UTF-8 | export LC_ALL=C.UTF-8 | ||||
set -euxo pipefail | set -euxo pipefail | ||||
DEFAULT_PARENT_COMMIT="origin/master" | |||||
help_message() { | help_message() { | ||||
set +x | cat <<EOF | ||||
echo "Generate a commit from available recipes." | Generate a commit from available recipes. | ||||
echo | |||||
echo "Options:" | |||||
echo "-p, --parent The parent commit to build ontop of. Default: '${DEFAULT_PARENT_COMMIT}'" | |||||
echo " Note: This should only be used for testing since the behavior of setting" | |||||
echo " this to a particular commit varies slightly from the default." | |||||
echo "-h, --help Display this help message." | |||||
echo | |||||
echo "Environment Variables:" | |||||
echo "COMMIT_TYPE (required) The commit recipe to run." | |||||
echo "DRY_RUN If set to 'no', this script will push the generated changes upstream. Default: 'yes'" | |||||
set -x | |||||
} | |||||
PARENT_COMMIT="${DEFAULT_PARENT_COMMIT}" | Options: | ||||
-h, --help Display this help message. | |||||
Environment Variables: | |||||
COMMIT_TYPE (required) The commit recipe to run. | |||||
EOF | |||||
} | |||||
# Parse command line arguments | # Parse command line arguments | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
-p|--parent) | |||||
PARENT_COMMIT=$(git rev-parse "$2") | |||||
shift # shift past argument | |||||
shift # shift past value | |||||
;; | |||||
-h|--help) | -h|--help) | ||||
help_message | help_message | ||||
exit 0 | exit 0 | ||||
;; | ;; | ||||
*) | *) | ||||
echo "Unknown argument: $1" | echo "Unknown argument: $1" | ||||
help_message | help_message | ||||
exit 1 | exit 1 | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
: "${COMMIT_TYPE:=}" | : "${COMMIT_TYPE:=}" | ||||
if [ -z "${COMMIT_TYPE}" ]; then | if [ -z "${COMMIT_TYPE}" ]; then | ||||
echo "Error: Environment variable COMMIT_TYPE must be set" | echo "Error: Environment variable COMMIT_TYPE must be set" | ||||
exit 2 | exit 2 | ||||
fi | fi | ||||
GIT_PUSH_OPTIONS=("--verbose") | # Make sure tree is clean | ||||
case ${DRY_RUN:=yes} in | if [ -n "$(git status --porcelain)" ]; then | ||||
no|NO|false|FALSE) | echo "Error: The source tree has unexpected changes. Clean up any changes (try 'git stash') and try again." | ||||
if [ "${PARENT_COMMIT}" != "${DEFAULT_PARENT_COMMIT}" ]; then | exit 10 | ||||
echo "Error: Running with DRY_RUN=no on a commit parent other than '${DEFAULT_PARENT_COMMIT}'" | |||||
exit 3 | |||||
fi | fi | ||||
;; | |||||
*) | |||||
GIT_PUSH_OPTIONS+=("--dry-run") | |||||
;; | |||||
esac | |||||
echo "Building automated commit '${COMMIT_TYPE}'..." | echo "Building automated commit '${COMMIT_TYPE}'..." | ||||
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-${COMMIT_TYPE}" | ||||
mkdir -p "${BUILD_DIR}" | mkdir -p "${BUILD_DIR}" | ||||
export BUILD_DIR | export BUILD_DIR | ||||
DEVTOOLS_DIR="${TOPLEVEL}"/contrib/devtools | DEVTOOLS_DIR="${TOPLEVEL}"/contrib/devtools | ||||
# Make sure tree is clean | |||||
git checkout master | |||||
git reset --hard "${PARENT_COMMIT}" | |||||
# Common script to update the AUR packages. | # Common script to update the AUR packages. | ||||
# Usage: update-aur-version <package_name> | # Usage: update-aur-version <package_name> | ||||
update-aur-version() { | update-aur-version() { | ||||
# shellcheck source=../utils/compare-version.sh | # shellcheck source=../utils/compare-version.sh | ||||
source "${TOPLEVEL}"/contrib/utils/compare-version.sh | source "${TOPLEVEL}"/contrib/utils/compare-version.sh | ||||
PACKAGE="$1" | PACKAGE="$1" | ||||
CURRENT_VERSION="" | CURRENT_VERSION="" | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | update-timings) | ||||
git commit -m "${BOT_PREFIX} Update timing.json" | git commit -m "${BOT_PREFIX} Update timing.json" | ||||
;; | ;; | ||||
*) | *) | ||||
echo "Error: Invalid commit name '${COMMIT_TYPE}'" | echo "Error: Invalid commit name '${COMMIT_TYPE}'" | ||||
exit 10 | exit 10 | ||||
;; | ;; | ||||
esac | esac | ||||
# Smoke tests to give some confidence that master won't be put into a bad state | |||||
"${DEVTOOLS_DIR}"/smoke-tests.sh | |||||
echo "Pushing automated commit '${COMMIT_TYPE}'..." | |||||
# Make sure master is up-to-date. If there is a merge conflict, this script | |||||
# will not attempt to resolve it and simply fail. | |||||
git fetch origin master | |||||
git rebase "${PARENT_COMMIT}" | |||||
git push "${GIT_PUSH_OPTIONS[@]}" origin master | |||||
deadalnix: You should be running the script that run the tests and land |
You should be running the script that run the tests and land