Skip to content

Commit 9c13c73

Browse files
authored
update backport script (#48)
1 parent 237b590 commit 9c13c73

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

.github/workflows/backport-2.0.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
jobs:
99
backport:
1010
runs-on: ubuntu-latest
11+
1112
steps:
1213
- name: Checkout repository
1314
uses: actions/checkout@v3
@@ -17,8 +18,15 @@ jobs:
1718
env:
1819
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1920
run: |
20-
PR_NUMBER=$(gh pr list --state merged --base main --json number --jq '.[0].number')
21+
# Get the latest commit hash on main
22+
COMMIT_HASH=$(git rev-parse HEAD)
23+
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
24+
25+
# Find the pull request associated with the commit
26+
PR_NUMBER=$(gh pr list --state merged --base main --json number,mergeCommit --jq ".[] | select(.mergeCommit == \"$COMMIT_HASH\").number")
2127
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
28+
29+
# Fetch the labels for the PR
2230
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name')
2331
echo "LABELS=$LABELS" >> $GITHUB_ENV
2432
@@ -50,11 +58,8 @@ jobs:
5058
git checkout $TARGET_BRANCH
5159
git checkout -b $BACKPORT_BRANCH
5260
53-
# Cherry-pick all commits from the PR
54-
COMMITS=$(gh pr view ${{ env.PR_NUMBER }} --json commits --jq '.commits[].oid')
55-
for COMMIT in $COMMITS; do
56-
git cherry-pick $COMMIT || (git cherry-pick --abort && exit 1)
57-
done
61+
# Cherry-pick the merge commit
62+
git cherry-pick ${{ env.COMMIT_HASH }} || (git cherry-pick --abort && exit 1)
5863
5964
# Push the new branch
6065
git push origin $BACKPORT_BRANCH

0 commit comments

Comments
 (0)