Skip to content

Commit 3184ed5

Browse files
committed
Add script to update release tracker on pr merge (#41)
/cherry-pick Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent fa39e11 commit 3184ed5

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

.github/workflows/cherry-pick.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ jobs:
1313
- uses: actions/checkout@v1
1414

1515
- name: Prepare git
16+
env:
17+
GITHUB_USER: 1gtm
18+
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
1619
run: |
17-
git config --global user.name "1gtm"
18-
git config --global user.email "1gtm@appscode.com"
20+
git config --global user.name "${GITHUB_USER}"
21+
git config --global user.email "${GITHUB_USER}@appscode.com"
22+
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
1923
2024
- name: Install GitHub CLI
2125
run: |

.github/workflows/release-tracker.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release-tracker
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v1
13+
14+
- name: Prepare git
15+
env:
16+
GITHUB_USER: 1gtm
17+
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
18+
run: |
19+
git config --global user.name "${GITHUB_USER}"
20+
git config --global user.email "${GITHUB_USER}@appscode.com"
21+
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
22+
23+
- name: Install GitHub CLI
24+
run: |
25+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
26+
sudo mv bin/hub /usr/local/bin
27+
28+
- name: Update release tracker
29+
if: |
30+
github.event.action == 'closed' &&
31+
github.event.pull_request.merged == true
32+
env:
33+
GITHUB_USER: 1gtm
34+
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
35+
run: |
36+
./hack/scripts/update-release-tracker.sh

hack/scripts/cherry-pick.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ should_cherry_pick || {
3131
exit 0
3232
}
3333

34-
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
35-
3634
while IFS=/ read -r -u9 repo branch; do
3735
git checkout $branch
3836
pr_branch="master-${GITHUB_SHA:0:8}"${branch#"release"}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
# ref: https://gist.github.com/joshisa/297b0bc1ec0dcdda0d1625029711fa24
20+
parse_url() {
21+
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
22+
# remove the protocol
23+
url="$(echo ${1/$proto/})"
24+
25+
IFS='/' # / is set as delimiter
26+
read -ra PARTS <<<"$url" # str is read into an array as tokens separated by IFS
27+
if [ ${PARTS[0]} != 'github.com' ] || [ ${#PARTS[@]} -ne 5 ]; then
28+
echo "failed to parse relase-tracker: $url"
29+
exit 1
30+
fi
31+
export RELEASE_TRACKER_OWNER=${PARTS[1]}
32+
export RELEASE_TRACKER_REPO=${PARTS[2]}
33+
export RELEASE_TRACKER_PR=${PARTS[4]}
34+
}
35+
36+
RELEASE_TRACKER=
37+
38+
while IFS=$': \r\t' read -r -u9 marker v; do
39+
case $marker in
40+
Release-tracker)
41+
export RELEASE_TRACKER=$v
42+
;;
43+
Release)
44+
export RELEASE=$v
45+
;;
46+
esac
47+
done 9< <(git show -s --format=%b)
48+
49+
[ ! -z $RELEASE_TRACKER ] || {
50+
echo "Release-tracker url not found."
51+
exit 0
52+
}
53+
54+
parse_url $RELEASE_TRACKER
55+
api_url="repos/${RELEASE_TRACKER_OWNER}/${RELEASE_TRACKER_REPO}/issues/${RELEASE_TRACKER_PR}/comments"
56+
57+
case $GITHUB_BASE_REF in
58+
master)
59+
msg="/ready-to-tag github.com/${GITHUB_REPOSITORY} ${GITHUB_SHA}"
60+
;;
61+
*)
62+
msg="/cherry-picked github.com/${GITHUB_REPOSITORY} ${GITHUB_BASE_REF} ${GITHUB_SHA}"
63+
;;
64+
esac
65+
66+
hub api "$api_url" -f body="$msg"

0 commit comments

Comments
 (0)