-
Notifications
You must be signed in to change notification settings - Fork 1
56 lines (49 loc) · 1.84 KB
/
spring-cherry-pick.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
name: Automatically cherry-pick commit
on:
workflow_call:
inputs:
autoCherryPickToken:
description: 'The sub-string in the commit message to determine that commit has to be cherry-picked'
required: false
default: Auto-cherry-pick to
type: string
secrets:
GH_ACTIONS_REPO_TOKEN:
required: true
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
jobs:
cherry-pick:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, inputs.autoCherryPickToken)
steps:
- uses: actions/checkout@v4
with:
token: ${{ env.GITHUB_TOKEN }}
show-progress: false
fetch-depth: 0
- name: Cherry-pick to branches in commit message
env:
CHERRY_PICK_TOKEN: ${{ inputs.autoCherryPickToken }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
git config --global user.name 'Spring Builds'
git config --global user.email '[email protected]'
branches=$(echo "$COMMIT_MESSAGE" | grep "$CHERRY_PICK_TOKEN" | grep -o1 -E "([0-9]+\.[0-9]+\.x)")
for branch in $branches
do
if [ "$branch" != '${{ github.ref_name }}' ]
then
git checkout "$branch"
if git cherry-pick ${{ github.sha }} -x
then
echo "::notice title=Commit cherry-picked::${{ github.sha }} to branch $branch"
else
echo "::error title=Cannot cherry-pick::${{ github.sha }} to branch $branch. Manual procedure required"
exit 1
fi
branchCommitMessage=$(git log -1 --pretty=%B | grep -v "$CHERRY_PICK_TOKEN")
git commit --amend -o -m "$branchCommitMessage"
git push origin $branch
fi
done