Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions doc/dev/releases/backport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
#
# Usage:
#
# $ VERSION=X.Y.Z PR=<pr-number> ./backport.sh
# $ VERSION=X.Y.Z PR=<pr-number> [PR_ONLY] [DUNE_REMOTE] ./backport.sh
#
# where
#
# - X.Y.Z is the version of Dune being released
# - <pr-number> is the number of a PR merged into main that needs backporting
# - The optional PR_ONLY, if `true`, will open a PR from the current branch,
# without preparing the backport cherry pick
# - The optional DUNE_REMOTE can be used to set name of the git remote to use as
# the bases for created PRs. It defaults to 'git config remote.pushdefault',
# if set, or finally to 'origin', if not.
#
# E.g.,
#
# $ VERSION=3.22.1 PR=1234 ./backport.sh
#
# If you have had to manually resolve merge conflicts from the cherry-pick, then
# you can rerun the script from the created backport branch with PR_ONLY=true, open
# the PR into the release branch. E.g.,
# you can rerun the script from the created backport branch with PR_ONLY=true,
# open the PR into the release branch. E.g.,
#
# $ PR_ONLY=true VERSION=X.Y.Z PR=<pr-number> ./backport.sh
#

set -xe
set -o pipefail
Expand All @@ -32,6 +40,10 @@ command -v gh >/dev/null 2>&1 || (echo >&2 "script requires gh"; exit 1)
[ ! -z "${PR}" ] || (echo >&2 "error: variable 'PR' is not set"; exit 1)
[ ! -z "${VERSION}" ] || (echo >&2 "error: variable 'VERSION' is not set"; exit 1)
PR_ONLY=${PR_ONLY:-false}
# Get the remote configured by envvar, or via the git config remote.pushDefault,
DUNE_REMOTE=${DUNE_REMOTE:-$(git config remote.pushdefault || echo "")}
# Finally fallback to 'origin' if the remote isn't configured
DUNE_REMOTE=${DUNE_REMOTE:-"origin"}

# All variables should be set from this point on
set -u
Expand All @@ -41,8 +53,9 @@ set -u
rc_branch="${VERSION}-rc"
backport_branch="backport-${PR}"

configured_remote=$(git config remote.pushdefault || echo "")
remote=${configured_remote:-"origin"}
# The github owner of the repo
# Required to avoid a manual prompt (see https://github.com/cli/cli/issues/5009)
github_owner=$(git remote get-url "${DUNE_REMOTE}" | sed -E 's#.*github\.com[:/]([^/]+).*#\1#')

if [ "${PR_ONLY}" == false ]
then
Expand All @@ -58,12 +71,13 @@ then
fi

git checkout -b "${backport_branch}"
git push -u "${remote}" HEAD
git push -u "${DUNE_REMOTE}" HEAD
git cherry-pick --mainline 1 --signoff -x "${commit}"
fi

gh pr create \
--repo ocaml/dune \
--base "${rc_branch}" \
--head "${github_owner}:${rc_branch}" \
--title "[${VERSION}] backport #${PR}" \
--body "Backport #${PR} onto ${rc_branch}"
Loading