[CI] Auto commit changes in auto-generated files (#127811) (#127911)

(cherry picked from commit 76f491b81d)

# Conflicts:
#	.buildkite/scripts/steps/checks/bazel_packages.sh
This commit is contained in:
Brian Seeders 2022-03-16 16:09:45 -04:00 committed by GitHub
parent 136b30f345
commit ee82479b25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 8 deletions

View file

@ -19,7 +19,7 @@ if ! yarn kbn bootstrap; then
fi
if [[ "$DISABLE_BOOTSTRAP_VALIDATION" != "true" ]]; then
verify_no_git_changes 'yarn kbn bootstrap'
check_for_changed_files 'yarn kbn bootstrap'
fi
###

View file

@ -14,17 +14,46 @@ is_pr() {
false
}
verify_no_git_changes() {
check_for_changed_files() {
RED='\033[0;31m'
YELLOW='\033[0;33m'
C_RESET='\033[0m' # Reset color
SHOULD_AUTO_COMMIT_CHANGES="${2:-}"
GIT_CHANGES="$(git ls-files --modified -- . ':!:.bazelrc')"
if [ "$GIT_CHANGES" ]; then
echo -e "\n${RED}ERROR: '$1' caused changes to the following files:${C_RESET}\n"
echo -e "$GIT_CHANGES\n"
echo -e "\n${YELLOW}TO FIX: Run '$1' locally, commit the changes and push to your branch${C_RESET}\n"
exit 1
if [[ "$SHOULD_AUTO_COMMIT_CHANGES" == "true" && "${BUILDKITE_PULL_REQUEST:-}" ]]; then
NEW_COMMIT_MESSAGE="[CI] Auto-commit changed files from '$1'"
PREVIOUS_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
if [[ "$NEW_COMMIT_MESSAGE" == "$PREVIOUS_COMMIT_MESSAGE" ]]; then
echo -e "\n${RED}ERROR: '$1' caused changes to the following files:${C_RESET}\n"
echo -e "$GIT_CHANGES\n"
echo -e "CI already attempted to commit these changes, but the file(s) seem to have changed again."
echo -e "Please review and fix manually."
exit 1
fi
echo "'$1' caused changes to the following files:"
echo "$GIT_CHANGES"
echo ""
echo "Auto-committing these changes now. A new build should start soon if successful."
git config --global user.name kibanamachine
git config --global user.email '42973632+kibanamachine@users.noreply.github.com'
gh pr checkout "${BUILDKITE_PULL_REQUEST}"
git add -u -- . ':!.bazelrc'
git commit -m "$NEW_COMMIT_MESSAGE"
git push
exit 1
else
echo -e "\n${RED}ERROR: '$1' caused changes to the following files:${C_RESET}\n"
echo -e "$GIT_CHANGES\n"
echo -e "\n${YELLOW}TO FIX: Run '$1' locally, commit the changes and push to your branch${C_RESET}\n"
exit 1
fi
fi
}

View file

@ -7,4 +7,4 @@ source .buildkite/scripts/common/util.sh
echo "--- Building kbn-pm distributable"
yarn kbn run build -i @kbn/pm
verify_no_git_changes 'yarn kbn run build -i @kbn/pm'
check_for_changed_files 'yarn kbn run build -i @kbn/pm' true

View file

@ -7,4 +7,4 @@ source .buildkite/scripts/common/util.sh
echo "--- Building plugin list docs"
node scripts/build_plugin_list_docs
verify_no_git_changes 'node scripts/build_plugin_list_docs'
check_for_changed_files 'node scripts/build_plugin_list_docs' true