| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Copyright 2020 The IREE Authors |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 4 | # |
| Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 5 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 8 | |
| 9 | # Checks out a branch at the specified green commit (default "main") and |
| 10 | # creates a PR from that branch based on google. |
| 11 | # |
| 12 | # - Requries the gh CLI (https://github.com/cli/cli) to create a PR. |
| 13 | # - Will force push to the configured PR_BRANCH (default "main-to-google") on |
| Geoffrey Martin-Noble | d1390ff | 2020-07-16 12:59:40 -0700 | [diff] [blame] | 14 | # the configured FORK_REMOTE (default "origin") |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 15 | # - Requires that local "main" branch is a pristine (potentially stale) copy |
| 16 | # of the "main" branch on the configured UPSTREAM_REMOTE |
| 17 | # (default "upstream"). |
| 18 | # - Requires that the working directory be clean. Will abort otherwise. |
| 19 | |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 20 | set -e |
| 21 | set -o pipefail |
| 22 | |
| 23 | GREEN_COMMIT="${1:-main}" |
| 24 | |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 25 | export UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 26 | PR_BRANCH="${PR_BRANCH:-main-to-google}" |
| Geoffrey Martin-Noble | d1390ff | 2020-07-16 12:59:40 -0700 | [diff] [blame] | 27 | FORK_REMOTE="${FORK_REMOTE:-origin}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 28 | |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 29 | ./scripts/git/git_update.sh main |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 30 | if [[ "${GREEN_COMMIT}" != "main" ]]; then |
| 31 | git checkout "${GREEN_COMMIT?}" |
| 32 | git submodule update |
| 33 | fi |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 34 | |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 35 | git checkout -B "${PR_BRANCH?}" |
| 36 | git push -f "${FORK_REMOTE?}" "${PR_BRANCH?}" |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 37 | |
| 38 | TITLE="Merge main -> google" |
| 39 | |
| 40 | git fetch "${UPSTREAM_REMOTE?}" google |
| Geoffrey Martin-Noble | cc84c18 | 2020-08-11 14:15:15 -0700 | [diff] [blame] | 41 | BODY="$(./scripts/git/summarize_changes.sh ${UPSTREAM_REMOTE?}/google)" |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 42 | |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 43 | if [[ -z "$(which gh)" ]]; then |
| 44 | echo "gh not found on path." |
| 45 | echo "Have you installed the GitHub CLI (https://github.com/cli/cli)?" |
| Geoffrey Martin-Noble | cbb02f5 | 2020-07-16 17:17:44 -0700 | [diff] [blame] | 46 | echo "Cannot create PR. Branch ${PR_BRANCH?} pushed, but aborting." |
| 47 | echo "You can manually create a PR using the generated body:" |
| 48 | echo "${BODY?}" |
| Geoffrey Martin-Noble | 7d76cbd | 2020-07-16 09:35:22 -0700 | [diff] [blame] | 49 | exit 1 |
| 50 | fi |
| Geoffrey Martin-Noble | 9167004 | 2020-10-02 13:58:04 -0700 | [diff] [blame] | 51 | |
| Geoffrey Martin-Noble | 7e5fa97 | 2021-08-17 13:56:20 -0700 | [diff] [blame] | 52 | # Extract the GitHub owner of the fork from either an ssh or https GitHub URL. |
| 53 | # Workaround for https://github.com/cli/cli/issues/1820, |
| 54 | # https://github.com/cli/cli/issues/1985, and |
| 55 | # https://github.com/cli/cli/issues/575 |
| 56 | FORK_NAME="$(git remote get-url ${FORK_REMOTE?} | sed 's|.*[/:]\([A-Za-z]*\)/iree\(.git\)\?|\1|')" |
| 57 | gh pr create --base google --head="${FORK_NAME?}:${PR_BRANCH?}" --title="${TITLE?}" --body="${BODY?}" |