Skip to content

Commit e08ed1a

Browse files
authored
[CI] Pick SHA of commit to cherry-pick from merge commit (#3167)
Previous logic was picking commits with committer's SHA. But instead we should cherry-pick the merge commit itself. TODO: if a PR is merged with "Rebase and Merge" strategy current logic will pick only the last commit. We usually don't merged like this, yet for rare accousions we should gather all of the merged commits. Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 5cf776c commit e08ed1a

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

.github/workflows/backport-to-branch.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,38 @@ jobs:
7777
git fetch origin ${{ env.TARGET }}:${{ env.TARGET }}
7878
git checkout -b backport/pr-${{ github.event.issue.number }}-to-${{ env.TARGET }} origin/${{ env.TARGET }}
7979
80-
- name: Get list of PR commits
80+
- name: Get commit sha
8181
id: commits
8282
uses: actions/github-script@v7
8383
with:
84+
github-token: ${{ secrets.GITHUB_TOKEN }}
8485
result-encoding: string
8586
script: |
86-
const { data } = await github.rest.pulls.listCommits({
87+
const pr = await github.rest.pulls.get({
8788
owner: context.repo.owner,
8889
repo: context.repo.repo,
8990
pull_number: context.issue.number
9091
});
91-
return data.map(c => c.sha).join(' ');
92+
# FIXME: handle PRs that are merged with "Rebase and Merge" strategy
93+
const sha = pr.data.merge_commit_sha;
94+
if (!sha) {
95+
throw new Error(`No merge_commit_sha found.`);
96+
}
97+
return sha;
9298
93-
- name: Cherry-pick commits
99+
- name: Cherry-pick commit
94100
id: cherry
95101
run: |
96102
conflict=false
97-
for sha in ${{ steps.commits.outputs.result }}; do
98-
echo "Cherry-picking $sha"
99-
if git cherry-pick "$sha"; then
100-
echo "$sha"
101-
else
102-
echo "Conflict on $sha"
103-
conflict=true
104-
echo "CONFLICT_SHA=$sha" >> $GITHUB_ENV
105-
break
106-
fi
107-
done
103+
SHA="${{ steps.merge_sha.outputs.result }}"
104+
echo "Cherry-picking squash-merge commit $SHA"
105+
if git cherry-pick "$SHA"; then
106+
echo "Cherry-picked $SHA"
107+
else
108+
echo "Conflict on $SHA"
109+
conflict=true
110+
echo "CONFLICT_SHA=$SHA" >> $GITHUB_ENV
111+
fi
108112
echo "CONFLICT=$conflict" >> $GITHUB_ENV
109113
110114
- name: Notify conflict

0 commit comments

Comments
 (0)