blob: 720c5d843af83c59e6eecb1cd1bfd4c8e08544c7 [file] [log] [blame]
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -07001#!/bin/bash
2
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003# Copyright 2020 The IREE Authors
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -07004#
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07005# 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-Noble7d76cbd2020-07-16 09:35:22 -07008
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-Nobled1390ff2020-07-16 12:59:40 -070014# the configured FORK_REMOTE (default "origin")
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070015# - 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-Noble7d76cbd2020-07-16 09:35:22 -070020set -e
21set -o pipefail
22
23GREEN_COMMIT="${1:-main}"
24
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070025export UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}"
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070026PR_BRANCH="${PR_BRANCH:-main-to-google}"
Geoffrey Martin-Nobled1390ff2020-07-16 12:59:40 -070027FORK_REMOTE="${FORK_REMOTE:-origin}"
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070028
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070029./scripts/git/git_update.sh main
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070030if [[ "${GREEN_COMMIT}" != "main" ]]; then
31 git checkout "${GREEN_COMMIT?}"
32 git submodule update
33fi
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070034
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070035git checkout -B "${PR_BRANCH?}"
36git push -f "${FORK_REMOTE?}" "${PR_BRANCH?}"
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070037
38TITLE="Merge main -> google"
39
40git fetch "${UPSTREAM_REMOTE?}" google
Geoffrey Martin-Noblecc84c182020-08-11 14:15:15 -070041BODY="$(./scripts/git/summarize_changes.sh ${UPSTREAM_REMOTE?}/google)"
Geoffrey Martin-Noblecbb02f52020-07-16 17:17:44 -070042
Geoffrey Martin-Noble7d76cbd2020-07-16 09:35:22 -070043if [[ -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-Noblecbb02f52020-07-16 17:17:44 -070046 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-Noble7d76cbd2020-07-16 09:35:22 -070049 exit 1
50fi
Geoffrey Martin-Noble91670042020-10-02 13:58:04 -070051
Geoffrey Martin-Noble7e5fa972021-08-17 13:56:20 -070052# 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
56FORK_NAME="$(git remote get-url ${FORK_REMOTE?} | sed 's|.*[/:]\([A-Za-z]*\)/iree\(.git\)\?|\1|')"
57gh pr create --base google --head="${FORK_NAME?}:${PR_BRANCH?}" --title="${TITLE?}" --body="${BODY?}"