Skip to content

Commit cf2d0a5

Browse files
1gtmtamalsaha
andauthored
[cherry-pick] Add workflow to cherry pick commits to master (#28) (#30)
/cherry-pick Signed-off-by: Tamal Saha <tamal@appscode.com> Co-authored-by: Tamal Saha <tamal@appscode.com>
1 parent b983837 commit cf2d0a5

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

.github/workflows/cherry-pick.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: cherry-pick
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v1
14+
15+
- name: Prepare git
16+
run: |
17+
git config --global user.name "1gtm"
18+
git config --global user.email "1gtm@appscode.com"
19+
20+
- name: Install GitHub CLI
21+
run: |
22+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
23+
sudo mv bin/hub /usr/local/bin
24+
25+
- name: Update release branches
26+
env:
27+
GITHUB_USER: 1gtm
28+
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
29+
run: |
30+
./hack/scripts/cherry-pick.sh

hack/scripts/cherry-pick.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Copyright The Stash Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eou pipefail
18+
19+
should_cherry_pick() {
20+
while IFS=$': \t' read -r -u9 marker v; do
21+
if [ "$marker" = "/cherry-pick" ]; then
22+
return 0
23+
fi
24+
done 9< <(git show -s --format=%b)
25+
return 1
26+
}
27+
28+
should_cherry_pick || {
29+
echo "Skipped cherry picking."
30+
echo "To automatically cherry pick, add /cherry-pick to commit message body."
31+
exit 0
32+
}
33+
34+
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
35+
36+
while IFS=/ read -r -u9 repo branch; do
37+
git checkout $branch
38+
pr_branch="master-${GITHUB_SHA:0:8}"${branch#"release"}
39+
git checkout -b $pr_branch
40+
git cherry-pick --strategy=recursive -X theirs $GITHUB_SHA
41+
git push -u origin HEAD -f
42+
hub pull-request \
43+
--base $branch \
44+
--labels automerge \
45+
--message "[cherry-pick] $(git show -s --format=%s)" \
46+
--message "$(git show -s --format=%b | sed --expression='/\/cherry-pick/d')" || true
47+
sleep 2
48+
done 9< <(git branch -r | grep release)

0 commit comments

Comments
 (0)