blob: bd7fb79087ff1b022c3ab5375cc47abba6ea880d [file] [log] [blame]
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -07001#!/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-Nobled1390ff2020-07-16 12:59:40 -070022# on the configured FORK_REMOTE (default "origin")
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070023# - 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
28set -e
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070029set -o pipefail
30
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070031export UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}"
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070032BASE_BRANCH="${1:-google}"
33PR_BRANCH="bazel-to-cmake-fix"
Geoffrey Martin-Nobled1390ff2020-07-16 12:59:40 -070034FORK_REMOTE="${FORK_REMOTE:-origin}"
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070035
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070036./scripts/git/git_update.sh "${BASE_BRANCH?}"
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070037git checkout -B "${PR_BRANCH?}"
38./build_tools/bazel_to_cmake/bazel_to_cmake.py
39
40TITLE="Run Bazel -> CMake"
41BODY='Updates CMake files to match Bazel BUILD
42
43\`./build_tools/bazel_to_cmake/bazel_to_cmake.py\`
44'
45
46git commit -am "${TITLE?}"
47git push -f "${FORK_REMOTE}" "${PR_BRANCH?}"
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070048
49if [[ -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
56fi
57
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070058gh pr create --title="${TITLE?}" --body="${BODY?}" --base="${BASE_BRANCH?}"