Skip to content

Commit 8eb4c84

Browse files
authored
chore: update cherrypick script (#7525)
Signed-off-by: zirain <[email protected]>
1 parent fe44f2c commit 8eb4c84

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tools/hack/cherrypick-for-patch-release.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# shellcheck disable=SC2207,SC2145,SC2181
44

55
REPO=${REPO:-"envoyproxy/gateway"}
6-
LABEL=${LABEL:-"cherrypick/release-v1.5.1"}
6+
LABEL=${LABEL:-"cherrypick/release-v1.5.5"}
77
DRY_RUN=${DRY_RUN:-true}
88
# SKIP specific PR numbers, e.g. "123 456" after resolved conflicts.
9+
# TODO: can we read this from git hist?
910
SKIP_PR_NUMBERS=${SKIP_PR_NUMBERS:-""}
1011

1112
if ! command -v jq >/dev/null 2>&1; then
@@ -36,9 +37,10 @@ if [[ "$CURRENT_BRANCH" == "main" || "$CURRENT_BRANCH" == "master" ]]; then
3637
fi
3738

3839
# current branch should create from the target release branch
39-
# e.g. for LABEL=cherrypick/release-v1.5.1
40+
# e.g. for LABEL=cherrypick/release-v1.5.5
4041
# git checkout release/v1.5
41-
# git checkout -b cherry-pick/v1.5.1
42+
# git pull
43+
# git checkout -b cherry-pick/v1.5.5
4244
BRANCH_SUFFIX=${LABEL#cherrypick/release-}
4345
TARGET_BRANCH="cherry-pick/$BRANCH_SUFFIX"
4446
if [[ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]]; then
@@ -47,10 +49,16 @@ if [[ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]]; then
4749
fi
4850

4951
# get all merged PR numbers with the specified label, sorted by merged date ascending
50-
PR_NUMBERS=($(curl -s -H "Authorization: token $GITHUB_TOKEN" \
51-
"https://api.github.com/repos/$REPO/pulls?state=closed&per_page=100" | \
52+
# the max items per page is 100, so we only get the first 100 PRs here
53+
# for more PRs, we need to implement pagination
54+
PAGES=(4 3 2 1)
55+
for page in "${PAGES[@]}"; do
56+
PAGE_PR_NUMBERS=($(curl -s -H "Authorization: token $GITHUB_TOKEN" \
57+
"https://api.github.com/repos/$REPO/pulls?state=closed&per_page=100&page=$page" | \
5258
jq -r ".[] | select(.labels[].name==\"$LABEL\" and .merged_at!=null) | {number, merged_at}" | \
5359
jq -s "sort_by(.merged_at) | .[].number"))
60+
PR_NUMBERS+=("${PAGE_PR_NUMBERS[@]}")
61+
done
5462

5563
echo "Total PRs to cherry-pick: ${#PR_NUMBERS[@]}"
5664
echo "PR_NUMBERS: ${PR_NUMBERS[@]}"
@@ -66,20 +74,21 @@ for PR in "${PR_NUMBERS[@]}"; do
6674
"https://api.github.com/repos/$REPO/pulls/$PR" | \
6775
jq -r ".merge_commit_sha")
6876

77+
if [[ "$DRY_RUN" == "true" ]]; then
78+
echo "Dry run: git cherry-pick PR #$PR with SHA: $SHA"
79+
continue
80+
fi
81+
6982
echo "PR #$PR merge commit SHA: $SHA"
7083
if [[ -z "$SHA" || "$SHA" == "null" ]]; then
7184
echo "PR #$PR merge commit $SHA not found"
7285
exit 1
7386
fi
7487
echo "Cherry-pick PR #$PR commit $SHA"
75-
if [[ "$DRY_RUN" == "true" ]]; then
76-
echo "Dry run: git cherry-pick PR #$PR with SHA: $SHA"
77-
continue
78-
fi
7988
git cherry-pick "$SHA"
80-
make build
8189
if [[ $? -ne 0 ]]; then
8290
echo "Cherry-pick $SHA failed, please resolve conflicts and run the script again."
8391
exit 1
8492
fi
93+
make build
8594
done

0 commit comments

Comments
 (0)