Skip to content

Commit 4ec4dd8

Browse files
add release.sh to make release process easier
Signed-off-by: Ryotaro Banno <[email protected]>
1 parent 9805208 commit 4ec4dd8

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

release.sh

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/usr/bin/env bash
2+
3+
#set -x
4+
set -eu
5+
set -o pipefail
6+
7+
if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
8+
echo "ERROR: call me from the main branch."
9+
exit 1
10+
fi
11+
if [ "$(git rev-parse main)" != $(git rev-parse origin/main) ]; then
12+
echo "ERROR: run 'git pull' beforehand."
13+
exit 1
14+
fi
15+
16+
list-prs(){
17+
commit_range=$1
18+
shift
19+
# Get the commits related to the topic.
20+
git log --pretty=%h $commit_range -- "$@" | \
21+
# Group the commits in sets of 10.
22+
awk 'NR == 1 { a = $1 } NR != 1 && NR % 10 == 1 { print a; a = $1 } { a = a "," $1 } END { print a }' | \
23+
# Get the PRs of the commits.
24+
xargs -I@ gh pr list -s all -S @ --json mergedAt,title,url,author | \
25+
# Format the ChangeLog messages using the PRs info.
26+
jq -r '.[] | .mergedAt+"* "+.title+" by @"+.author.login+" in "+.url' | \
27+
sort -u | \
28+
sed -r 's/^[^*]+//'
29+
}
30+
31+
get-mantle-latest-tag(){
32+
git describe --tags --abbrev=0 --match='v*' | sed 's/^v//'
33+
}
34+
35+
case-mantle(){
36+
# Check Mantle's changes
37+
MANTLE_LATEST_TAG=$(get-mantle-latest-tag)
38+
MANTLE_PRS=$(list-prs v$MANTLE_LATEST_TAG...HEAD . ":^charts")
39+
if [ "$MANTLE_PRS" != "" ]; then
40+
echo "What's Changed:"
41+
echo
42+
echo "$MANTLE_PRS"
43+
echo
44+
echo "The current version is" $MANTLE_LATEST_TAG
45+
echo -n "Next version? (only numbers and dots accepted) "
46+
read NEXT_MANTLE_VERSION
47+
echo "Run the following code:"
48+
echo
49+
echo -e "\tgit switch main"
50+
echo -e "\tgit pull"
51+
echo -e "\tgit tag v${NEXT_MANTLE_VERSION}"
52+
echo -e "\tgit push origin v${NEXT_MANTLE_VERSION}"
53+
echo
54+
echo "Then, CI will draft a new release, so edit it to publish it."
55+
echo "After that, please run '$0 mantle-helm-chart'"
56+
else
57+
echo "You don't have to release Mantle."
58+
fi
59+
}
60+
61+
case-mantle-helm-chart(){
62+
# Check mantle Helm Chart changes
63+
MANTLE_HELM_CHART_LATEST_TAG=$(git describe --tags --abbrev=0 --match='mantle-chart-*')
64+
MANTLE_HELM_CHART_PRS=$(list-prs $MANTLE_HELM_CHART_LATEST_TAG...HEAD charts/mantle)
65+
66+
if [ "$MANTLE_HELM_CHART_PRS" != "" ]; then
67+
MANTLE_LATEST_TAG=$(get-mantle-latest-tag)
68+
echo "What's Changed:"
69+
echo
70+
echo "$MANTLE_HELM_CHART_PRS"
71+
echo
72+
echo "The detected Mantle version is" $MANTLE_LATEST_TAG
73+
echo "The current version is" $MANTLE_HELM_CHART_LATEST_TAG
74+
echo -n "Next version (only numbers and dots accepted)? "
75+
read MANTLE_HELM_CHART_NEXT_VERSION
76+
echo "Run the following code:"
77+
echo
78+
echo -e "\tAPPVERSION=$MANTLE_LATEST_TAG"
79+
echo -e "\tCHARTVERSION=$MANTLE_HELM_CHART_NEXT_VERSION"
80+
echo -e "\tgit switch main"
81+
echo -e "\tgit pull"
82+
echo -e "\tgit switch -c bump-mantle-chart-\${CHARTVERSION}"
83+
echo -e "\tsed -r -i" '"s/appVersion: \"[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\"/appVersion: \"${APPVERSION}\"/g" charts/mantle/Chart.yaml'
84+
echo -e "\tsed -r -i" '"s/^version: [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+/version: ${CHARTVERSION}/g" charts/mantle/Chart.yaml'
85+
echo -e "\tgit commit -a -s -m" '"Bump mantle chart version to ${CHARTVERSION}"'
86+
echo -e "\tgit push --set-upstream origin bump-mantle-chart-\${CHARTVERSION}"
87+
echo
88+
echo "Then,"
89+
echo "1. Create a PR and merge it."
90+
echo "2. Run CI https://github.com/cybozu-go/mantle/actions/workflows/helm-release.yaml to release the new Helm Chart."
91+
echo "3. Edit the release note."
92+
echo "4. Run '$0 mantle-cluster-wide-helm-chart'"
93+
else
94+
echo "You don't have to release mantle Helm Chart."
95+
fi
96+
}
97+
98+
case-mantle-cluster-wide-helm-chart(){
99+
# Check mantle-cluster-wide Helm Chart changes
100+
MANTLE_CLUSTER_WIDE_HELM_CHART_LATEST_TAG=$(git describe --tags --abbrev=0 --match='mantle-cluster-wide-chart-*')
101+
MANTLE_CLUSTER_WIDE_HELM_CHART_PRS=$(list-prs $MANTLE_CLUSTER_WIDE_HELM_CHART_LATEST_TAG...HEAD charts/mantle-cluster-wide)
102+
103+
if [ "$MANTLE_CLUSTER_WIDE_HELM_CHART_PRS" != "" ]; then
104+
echo "What's Changed:"
105+
echo
106+
echo "$MANTLE_CLUSTER_WIDE_HELM_CHART_PRS"
107+
echo
108+
echo "The current version is" $MANTLE_CLUSTER_WIDE_HELM_CHART_LATEST_TAG
109+
echo -n "Next version (only numbers and dots accepted)? "
110+
read MANTLE_CLUSTER_WIDE_HELM_CHART_NEXT_VERSION
111+
echo "Run the following code:"
112+
echo
113+
MANTLE_LATEST_TAG=$(get-mantle-latest-tag)
114+
echo -e "\tAPPVERSION=$MANTLE_LATEST_TAG"
115+
echo -e "\tCHARTVERSION=$MANTLE_CLUSTER_WIDE_HELM_CHART_NEXT_VERSION"
116+
echo -e "\tgit switch main"
117+
echo -e "\tgit pull"
118+
echo -e "\tgit" 'switch -c bump-mantle-cluster-wide-chart-${CHARTVERSION}'
119+
echo -e "\tsed" '-r -i "s/appVersion: \"[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\"/appVersion: \"${APPVERSION}\"/g" charts/mantle-cluster-wide/Chart.yaml'
120+
echo -e "\tsed" '-r -i "s/^version: [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+/version: ${CHARTVERSION}/g" charts/mantle-cluster-wide/Chart.yaml'
121+
echo -e "\tgit" 'commit -a -s -m "Bump mantle-cluster-wide chart version to ${CHARTVERSION}"'
122+
echo -e "\tgit" 'push --set-upstream origin bump-mantle-cluster-wide-chart-${CHARTVERSION}'
123+
echo
124+
echo "Then,"
125+
echo "1. Create a PR and merge it."
126+
echo "2. Run CI https://github.com/cybozu-go/mantle/actions/workflows/helm-release.yaml to release the new Helm Chart."
127+
echo "3. Edit the release note."
128+
else
129+
echo "You don't have to release mantle-cluster-wide Helm Chart."
130+
fi
131+
}
132+
133+
case "$@" in
134+
mantle )
135+
case-mantle
136+
;;
137+
138+
mantle-helm-chart )
139+
case-mantle-helm-chart
140+
;;
141+
142+
mantle-cluster-wide-helm-chart )
143+
case-mantle-cluster-wide-helm-chart
144+
;;
145+
146+
* )
147+
echo "Usage: $0 <command>"
148+
echo
149+
echo "Commands:"
150+
echo " mantle:"
151+
echo " Print instructions to release Mantle."
152+
echo " mantle-helm-chart:"
153+
echo " Print instructions to release mantle Helm Chart."
154+
echo " mantle-cluster-wide-helm-chart:"
155+
echo " Print instructions to release mantle-cluster-wide Helm Chart."
156+
;;
157+
esac

0 commit comments

Comments
 (0)