Skip to content

Commit b7a4542

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

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

release.sh

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

0 commit comments

Comments
 (0)