Skip to content
Merged
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
24 changes: 6 additions & 18 deletions sh/gh/back-merge.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
#
# Open (or refresh) the pull request that merges `release` back into `main`,
# and queue it to land as a merge commit once Check and Test pass.
# Open (or refresh) the pull request that merges `release` back into `main`.
# Check's `land` job merges it as a merge commit once Check and Test pass on its
# head, bypassing the squash-only merge queue.
#
# The pull request's head is its own branch rather than `release` itself: the
# repository deletes head branches on merge, and a conflict is resolved by
Expand Down Expand Up @@ -45,25 +46,12 @@ esac

# Only a pull request from this repository's own branch: `gh pr list --head`
# matches the branch name alone, so a fork's branch of the same name would pass.
find_pr() {
gh api "repos/$repo/pulls?state=open&base=main&head=${repo%%/*}:$branch" \
--jq "[.[] | select(.head.repo.full_name == \"$repo\")][0].number // empty"
}

pr=$(find_pr)
pr=$(gh api "repos/$repo/pulls?state=open&base=main&head=${repo%%/*}:$branch" \
--jq "[.[] | select(.head.repo.full_name == \"$repo\")][0].number // empty")
if [[ -z "$pr" ]]; then
gh pr create --repo "$repo" --head "$branch" --base main \
--title "chore: merge release into main" \
--body "Carries what \`release\` published (versions, CHANGELOGs, backports) back to trunk. Opened by the Back-merge workflow.

**Merge with a merge commit. Never squash.** A squash leaves the merge base at the last cut, so the next back-merge conflicts. On a conflict, merge \`main\` into \`$branch\` and resolve it there."
pr=$(find_pr)
fi
if [[ -z "$pr" ]]; then
echo "error: no pull request from $repo:$branch into main" >&2
exit 1
Check's \`land\` job merges it as a merge commit once Check and Test pass. **Never squash.** A squash leaves the merge base at the last cut, so the next back-merge conflicts. On a conflict, merge \`main\` into \`$branch\` and resolve it there."
fi

# Queue exactly the commit this run produced, so a later push cannot ride along.
head=$(gh api "repos/$repo/git/ref/heads/$branch" --jq .object.sha)
gh pr merge --repo "$repo" "$pr" --auto --merge --match-head-commit "$head"
Loading