| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2020 Google LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Creates a PR based on the specified BASE_BRANCH (default "google") to fix |
| 18 | # CMake files based on Bazel BUILD files. |
| 19 | # |
| 20 | # - Requries the gh CLI (https://github.com/cli/cli) to create a PR. |
| 21 | # - Will force push to the configured PR_BRANCH (default "bazel-to-cmake-fix") |
| Geoffrey Martin-Noble | d1390ff | 2020-07-16 12:59:40 -0700 | [diff] [blame] | 22 | # on the configured FORK_REMOTE (default "origin") |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 23 | # - Requires that local BASE_BRANCH branch is a pristine (potentially stale) |
| 24 | # copy of the same branch on the configured UPSTREAM_REMOTE |
| 25 | # (default "upstream"). |
| 26 | # - Requires that the working directory be clean. Will abort otherwise. |
| 27 | |
| 28 | set -e |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 29 | set -o pipefail |
| 30 | |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 31 | export UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 32 | BASE_BRANCH="${1:-google}" |
| 33 | PR_BRANCH="bazel-to-cmake-fix" |
| Geoffrey Martin-Noble | d1390ff | 2020-07-16 12:59:40 -0700 | [diff] [blame] | 34 | FORK_REMOTE="${FORK_REMOTE:-origin}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 35 | |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 36 | ./scripts/git/git_update.sh "${BASE_BRANCH?}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 37 | git checkout -B "${PR_BRANCH?}" |
| 38 | ./build_tools/bazel_to_cmake/bazel_to_cmake.py |
| 39 | |
| 40 | TITLE="Run Bazel -> CMake" |
| 41 | BODY='Updates CMake files to match Bazel BUILD |
| 42 | |
| 43 | \`./build_tools/bazel_to_cmake/bazel_to_cmake.py\` |
| 44 | ' |
| 45 | |
| 46 | git commit -am "${TITLE?}" |
| 47 | git push -f "${FORK_REMOTE}" "${PR_BRANCH?}" |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 48 | |
| 49 | if [[ -z "$(which gh)" ]]; then |
| 50 | echo "gh not found on path." |
| 51 | echo "Have you installed the GitHub CLI (https://github.com/cli/cli)?" |
| 52 | echo "Cannot create PR. Branch ${PR_BRANCH?} pushed, but aborting." |
| 53 | echo "You can manually create a PR using the generated body:" |
| 54 | echo "${BODY?}" |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 58 | gh pr create --title="${TITLE?}" --body="${BODY?}" --base="${BASE_BRANCH?}" |