mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #29873 from pmorie/cherry-pick-dry-run
Automatic merge from submit-queue Add dry run capability to cherry_pick_pull.sh When creating patches for downstream projects like OpenShift, I found it to be helpful to have a dry run mode for the cherry-pick script. @k8s-oncall cc @kubernetes/rh-cluster-infra
This commit is contained in:
commit
f8e9650ea5
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
# Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How
|
# Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How
|
||||||
# meta.) Assumes you care about pulls from remote "upstream" and
|
# meta.) Assumes you care about pulls from remote "upstream" and
|
||||||
# checks thems out to a branch named pull_12345.
|
# checks thems out to a branch named:
|
||||||
|
# automated-cherry-pick-of-<pr>-<target branch>-<timestamp>
|
||||||
|
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
@ -27,6 +28,7 @@ cd "${KUBE_ROOT}"
|
|||||||
|
|
||||||
declare -r STARTINGBRANCH=$(git symbolic-ref --short HEAD)
|
declare -r STARTINGBRANCH=$(git symbolic-ref --short HEAD)
|
||||||
declare -r REBASEMAGIC="${KUBE_ROOT}/.git/rebase-apply"
|
declare -r REBASEMAGIC="${KUBE_ROOT}/.git/rebase-apply"
|
||||||
|
DRY_RUN=${DRY_RUN:-""}
|
||||||
|
|
||||||
if [[ -z ${GITHUB_USER:-} ]]; then
|
if [[ -z ${GITHUB_USER:-} ]]; then
|
||||||
echo "Please export GITHUB_USER=<your-user> (or GH organization, if that's where your fork lives)"
|
echo "Please export GITHUB_USER=<your-user> (or GH organization, if that's where your fork lives)"
|
||||||
@ -40,11 +42,15 @@ fi
|
|||||||
|
|
||||||
if [[ "$#" -lt 2 ]]; then
|
if [[ "$#" -lt 2 ]]; then
|
||||||
echo "${0} <remote branch> <pr-number>...: cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
|
echo "${0} <remote branch> <pr-number>...: cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
|
||||||
echo ""
|
echo
|
||||||
echo " Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
|
echo " Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
|
||||||
echo " Examples:"
|
echo " Examples:"
|
||||||
echo " $0 upstream/release-3.14 12345 # Cherry-picks PR 12345 onto upstream/release-3.14 and proposes that as a PR."
|
echo " $0 upstream/release-3.14 12345 # Cherry-picks PR 12345 onto upstream/release-3.14 and proposes that as a PR."
|
||||||
echo " $0 upstream/release-3.14 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
|
echo " $0 upstream/release-3.14 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
|
||||||
|
echo
|
||||||
|
echo " Set the DRY_RUN environment var to skip git push and creating PR."
|
||||||
|
echo " This is useful for creating patches to a release branch without making a PR."
|
||||||
|
echo " When DRY_RUN is set the script will leave you in a branch containing the commits you cherry-picked."
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -67,7 +73,7 @@ declare -r PULLDASH=$(join - "${PULLS[@]/#/#}") # Generates something like "#123
|
|||||||
declare -r PULLSUBJ=$(join " " "${PULLS[@]/#/#}") # Generates something like "#12345 #56789"
|
declare -r PULLSUBJ=$(join " " "${PULLS[@]/#/#}") # Generates something like "#12345 #56789"
|
||||||
|
|
||||||
echo "+++ Updating remotes..."
|
echo "+++ Updating remotes..."
|
||||||
git remote update
|
git remote update upstream origin
|
||||||
|
|
||||||
if ! git log -n1 --format=%H "${BRANCH}" >/dev/null 2>&1; then
|
if ! git log -n1 --format=%H "${BRANCH}" >/dev/null 2>&1; then
|
||||||
echo "!!! '${BRANCH}' not found. The second argument should be something like upstream/release-0.21."
|
echo "!!! '${BRANCH}' not found. The second argument should be something like upstream/release-0.21."
|
||||||
@ -84,21 +90,46 @@ cleanbranch=""
|
|||||||
prtext=""
|
prtext=""
|
||||||
gitamcleanup=false
|
gitamcleanup=false
|
||||||
function return_to_kansas {
|
function return_to_kansas {
|
||||||
echo ""
|
|
||||||
echo "+++ Returning you to the ${STARTINGBRANCH} branch and cleaning up."
|
|
||||||
if [[ "${gitamcleanup}" == "true" ]]; then
|
if [[ "${gitamcleanup}" == "true" ]]; then
|
||||||
|
echo
|
||||||
|
echo "+++ Aborting in-progress git am."
|
||||||
git am --abort >/dev/null 2>&1 || true
|
git am --abort >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
git checkout -f "${STARTINGBRANCH}" >/dev/null 2>&1 || true
|
|
||||||
if [[ -n "${cleanbranch}" ]]; then
|
# return to the starting branch and delete the PR text file
|
||||||
git branch -D "${cleanbranch}" >/dev/null 2>&1 || true
|
if [[ -z "${DRY_RUN}" ]]; then
|
||||||
fi
|
echo
|
||||||
if [[ -n "${prtext}" ]]; then
|
echo "+++ Returning you to the ${STARTINGBRANCH} branch and cleaning up."
|
||||||
rm "${prtext}"
|
git checkout -f "${STARTINGBRANCH}" >/dev/null 2>&1 || true
|
||||||
|
if [[ -n "${cleanbranch}" ]]; then
|
||||||
|
git branch -D "${cleanbranch}" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
if [[ -n "${prtext}" ]]; then
|
||||||
|
rm "${prtext}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
trap return_to_kansas EXIT
|
trap return_to_kansas EXIT
|
||||||
|
|
||||||
|
function make-a-pr() {
|
||||||
|
local rel="$(basename "${BRANCH}")"
|
||||||
|
echo
|
||||||
|
echo "+++ Creating a pull request on GitHub at ${GITHUB_USER}:${NEWBRANCH}"
|
||||||
|
|
||||||
|
# This looks like an unnecessary use of a tmpfile, but it avoids
|
||||||
|
# https://github.com/github/hub/issues/976 Otherwise stdin is stolen
|
||||||
|
# when we shove the heredoc at hub directly, tickling the ioctl
|
||||||
|
# crash.
|
||||||
|
prtext="$(mktemp -t prtext.XXXX)" # cleaned in return_to_kansas
|
||||||
|
cat >"${prtext}" <<EOF
|
||||||
|
Automated cherry pick of ${PULLSUBJ}
|
||||||
|
|
||||||
|
Cherry pick of ${PULLSUBJ} on ${rel}.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
hub pull-request -F "${prtext}" -h "${GITHUB_USER}:${NEWBRANCH}" -b "kubernetes:${rel}"
|
||||||
|
}
|
||||||
|
|
||||||
git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}"
|
git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}"
|
||||||
cleanbranch="${NEWBRANCHUNIQ}"
|
cleanbranch="${NEWBRANCHUNIQ}"
|
||||||
|
|
||||||
@ -137,23 +168,17 @@ for pull in "${PULLS[@]}"; do
|
|||||||
done
|
done
|
||||||
gitamcleanup=false
|
gitamcleanup=false
|
||||||
|
|
||||||
function make-a-pr() {
|
if [[ -n "${DRY_RUN}" ]]; then
|
||||||
local rel="$(basename "${BRANCH}")"
|
echo "!!! Skipping git push and PR creation because you set DRY_RUN."
|
||||||
echo "+++ Creating a pull request on GitHub at ${GITHUB_USER}:${NEWBRANCH}"
|
echo "To return to the branch you were in when you invoked this script:"
|
||||||
|
echo
|
||||||
# This looks like an unnecessary use of a tmpfile, but it avoids
|
echo " git checkout ${STARTINGBRANCH}"
|
||||||
# https://github.com/github/hub/issues/976 Otherwise stdin is stolen
|
echo
|
||||||
# when we shove the heredoc at hub directly, tickling the ioctl
|
echo "To delete this branch:"
|
||||||
# crash.
|
echo
|
||||||
prtext="$(mktemp -t prtext.XXXX)" # cleaned in return_to_kansas
|
echo " git branch -D ${NEWBRANCHUNIQ}"
|
||||||
cat >"${prtext}" <<EOF
|
exit 0
|
||||||
Automated cherry pick of ${PULLSUBJ}
|
fi
|
||||||
|
|
||||||
Cherry pick of ${PULLSUBJ} on ${rel}.
|
|
||||||
EOF
|
|
||||||
|
|
||||||
hub pull-request -F "${prtext}" -h "${GITHUB_USER}:${NEWBRANCH}" -b "kubernetes:${rel}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if git remote -v | grep ^origin | grep kubernetes/kubernetes.git; then
|
if git remote -v | grep ^origin | grep kubernetes/kubernetes.git; then
|
||||||
echo "!!! You have 'origin' configured as your kubernetes/kubernetes.git"
|
echo "!!! You have 'origin' configured as your kubernetes/kubernetes.git"
|
||||||
|
Loading…
Reference in New Issue
Block a user