-
Notifications
You must be signed in to change notification settings - Fork 26
68 lines (59 loc) · 2.92 KB
/
cherry-pick-rc-to-develop.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: "Cherry-pick from rc to develop"
on:
pull_request:
branches:
- release/candidate
types:
- closed
jobs:
cherry-pick:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Append -cherry-pick to branch name
id: extract
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
NEW_BRANCH_NAME="${PR_BRANCH}-cherry-pick"
echo "New branch name: $NEW_BRANCH_NAME"
echo "newBranchName=$NEW_BRANCH_NAME" >> $GITHUB_ENV
- name: Check if changes only in kalium submodule
id: check_changes
run: |
NUM_CHANGES=$(git diff origin/develop --name-only | grep -v '^kalium/' | wc -l)
if [ "$NUM_CHANGES" -gt 0 ]; then
echo "::set-output name=shouldCherryPick::true"
else
echo "No changes outside of kalium submodule, skipping cherry-pick"
echo "::set-output name=shouldCherryPick::false"
fi
- uses: fregante/setup-git-user@v2
- name: Cherry-pick commits
id: cherry
if: steps.check_changes.outputs.shouldCherryPick == 'true'
run: |
git fetch origin develop:develop
git checkout -b ${{ env.newBranchName }} develop
# Cherry-picking the last commit on the base branch
OUTPUT=$(git cherry-pick ${{ github.event.pull_request.merge_commit_sha }} --strategy-option theirs || true)
CONFLICTS=$(echo "$OUTPUT" | grep 'CONFLICT' || echo "")
if [ -n "$CONFLICTS" ]; then
git add .
git cherry-pick --continue || true
fi
git push origin ${{ env.newBranchName }} || (echo "Failed to push to origin" && exit 1)
echo "conflicts=$CONFLICTS" >> $GITHUB_ENV
- name: Create PR
if: steps.check_changes.outputs.shouldCherryPick == 'true'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BRANCH: ${{ env.newBranchName }}
PR_ASSIGNEE: ${{ github.event.pull_request.user.login }}
PR_BODY: "${{ format('Cherry pick from the original PR: \n- #{0}\n\n---- \n\n ⚠️ Conflicts during cherry-pick:\n{1}\n\n{2}', github.event.pull_request.number, env.conflicts, github.event.pull_request.body) }}"
run: gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base develop --head "$PR_BRANCH" --label "cherry-pick" --assignee "$PR_ASSIGNEE"