Clean up maintenance scripts (#2550)
- Factor update into a separate script. It's pretty verbose.
- Fetch the base branch for doing comparisons in merge scripts.
- Have uniform error handling for missing `gh`
- Some other consistency between the scripts.
- Turn of `set -x`. Current script messaging is better than that
gets us.
Example PRs created by these scripts (because testing in prod
is the only testing):
https://github.com/google/iree/pull/2554
https://github.com/google/iree/pull/2555
https://github.com/google/iree/pull/2553
diff --git a/scripts/git/bazel_to_cmake.sh b/scripts/git/bazel_to_cmake.sh
index e5738fa..bd7fb79 100755
--- a/scripts/git/bazel_to_cmake.sh
+++ b/scripts/git/bazel_to_cmake.sh
@@ -26,32 +26,14 @@
# - Requires that the working directory be clean. Will abort otherwise.
set -e
-set -x
set -o pipefail
+export UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}"
BASE_BRANCH="${1:-google}"
PR_BRANCH="bazel-to-cmake-fix"
-UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}"
FORK_REMOTE="${FORK_REMOTE:-origin}"
-if [[ -n "$(git status --porcelain)" ]]; then
- echo "Working directory not clean. Aborting"
- git status
- exit 1
-fi
-if ! git symbolic-ref -q HEAD; then
- echo "In a detached HEAD state. Aborting"
- git status
- exit 1
-fi
-git checkout "${BASE_BRANCH?}"
-git pull "${UPSTREAM_REMOTE?}" "${BASE_BRANCH?}" --ff-only
-git submodule update --init
-if [[ -n "$(git status --porcelain)" ]]; then
- echo "Working directory not clean after sync. Aborting"
- git status
- exit 1
-fi
+./scripts/git/git_update.sh "${BASE_BRANCH?}"
git checkout -B "${PR_BRANCH?}"
./build_tools/bazel_to_cmake/bazel_to_cmake.py
@@ -63,4 +45,14 @@
git commit -am "${TITLE?}"
git push -f "${FORK_REMOTE}" "${PR_BRANCH?}"
+
+if [[ -z "$(which gh)" ]]; then
+ echo "gh not found on path."
+ echo "Have you installed the GitHub CLI (https://github.com/cli/cli)?"
+ echo "Cannot create PR. Branch ${PR_BRANCH?} pushed, but aborting."
+ echo "You can manually create a PR using the generated body:"
+ echo "${BODY?}"
+ exit 1
+fi
+
gh pr create --title="${TITLE?}" --body="${BODY?}" --base="${BASE_BRANCH?}"