1+ #! /usr/bin/env bash
2+ #
3+ # Copyright 2024 The Dapr Authors
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ # Unless required by applicable law or agreed to in writing, software
9+ # distributed under the License is distributed on an "AS IS" BASIS,
10+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ # See the License for the specific language governing permissions and
12+ # limitations under the License.
13+
14+ set -ue
15+
16+ script_dir=$( readlink -f $( dirname $0 ) )
17+ current_time=$( date +" %Y-%m-%d_%H-%M-%S" )
18+
19+ # Thanks to https://ihateregex.io/expr/semver/
20+ SEMVER_REGEX=' ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
21+
22+ REL_VERSION=` echo $1 | sed -r ' s/^[vV]?([0-9].+)$/\1/' `
23+
24+ if [ ` echo $REL_VERSION | pcre2grep " $SEMVER_REGEX " ` ]; then
25+ echo " $REL_VERSION is a valid semantic version."
26+ else
27+ echo " $REL_VERSION is not a valid semantic version."
28+ exit 1
29+ fi
30+
31+ MAJOR_MINOR_VERSION=` echo ${REL_VERSION} - | cut -d- -f1 | cut -d. -f1,2`
32+ MAJOR_MINOR_PATCH_VERSION=` echo ${REL_VERSION} - | cut -d- -f1 | cut -d. -f1,2,3`
33+ VARIANT=` echo ${REL_VERSION} - | cut -d- -f2`
34+
35+ if [ " $VARIANT " = " SNAPSHOT" ]; then
36+ echo " SNAPSHOT release detected, updating version in master branch to $REL_VERSION ..."
37+ if [ " $REL_VERSION " != " ${MAJOR_MINOR_PATCH_VERSION} -SNAPSHOT" ]; then
38+ echo " Invalid snapshot version: $REL_VERSION "
39+ exit 3
40+ fi
41+ branch_name=" automation/update_to_next_${current_time} "
42+ git checkout -b $branch_name
43+ ${script_dir} /update_sdk_version.sh $REL_VERSION
44+ git clean -xdf
45+ git commit -s -m " Update master version to ${$REL_VERSION } " -a
46+ git push origin $branch_name
47+ gh pr create --repo ${GITHUB_REPOSITORY} \
48+ --base master \
49+ --title " Update master version to ${$REL_VERSION } " \
50+ --body " Update master version to ${$REL_VERSION } "
51+ echo " Done."
52+ exit 0
53+ elif [ " $VARIANT " = " rc" ]; then
54+ echo " Release-candidate version detected: $REL_VERSION "
55+ RC_COUNT=` echo ${REL_VERSION} - | cut -d- -f3`
56+ if ! (( 10 #${RC_COUNT} >= 0 )) 2> /dev/null || [ " $RC_COUNT " == " " ]; then
57+ echo " Invalid release-candidate count: $RC_COUNT "
58+ exit 3
59+ fi
60+ if [ " $REL_VERSION " != " ${MAJOR_MINOR_PATCH_VERSION} -rc-${RC_COUNT} " ]; then
61+ echo " Invalid release-candidate version: $REL_VERSION "
62+ exit 3
63+ fi
64+ elif [ " $VARIANT " = " " ]; then
65+ echo " Release version detected: $REL_VERSION "
66+ else
67+ echo " Invalid release variant: $VARIANT "
68+ exit 3
69+ fi
70+
71+ echo " Passed all version format validations."
72+
73+ RELEASE_BRANCH=" release-$MAJOR_MINOR_VERSION "
74+ RELEASE_TAG=" v$REL_VERSION "
75+
76+ if [ ` git rev-parse --verify origin/$RELEASE_BRANCH 2> /dev/null` ]; then
77+ echo " $RELEASE_BRANCH branch already exists, checking it out ..."
78+ git checkout $RELEASE_BRANCH
79+ else
80+ echo " $RELEASE_BRANCH does not exist, creating ..."
81+ git checkout -b $RELEASE_BRANCH
82+ git push origin $RELEASE_BRANCH
83+ fi
84+ echo " $RELEASE_BRANCH branch is ready."
85+
86+ if [ ` git rev-parse --verify $RELEASE_TAG 2> /dev/null` ]; then
87+ echo " $RELEASE_TAG tag already exists, aborting ..."
88+ exit 2
89+ fi
90+
91+ ${script_dir} /update_sdk_version.sh $REL_VERSION
92+ git commit -s -m " Release $REL_VERSION " -a
93+ if [ " $VARIANT " = " " ]; then
94+ echo " Generating docs ..."
95+ ${script_dir} /update_docs.sh $REL_VERSION
96+ git commit -s -m " Generate updated javadocs for $REL_VERSION " -a
97+ fi
98+ git push origin $RELEASE_BRANCH
99+
100+ echo " Tagging $RELEASE_TAG ..."
101+ git tag $RELEASE_TAG
102+ echo " $RELEASE_TAG is tagged."
103+
104+ echo " Pushing $RELEASE_TAG tag ..."
105+ git push origin $RELEASE_TAG
106+ echo " $RELEASE_TAG tag is pushed."
107+
108+ if [ " $VARIANT " = " " ]; then
109+ git clean -xdf
110+ echo " Creating pull request to update docs ..."
111+ branch_name=" automation/update_docs_${current_time} "
112+ git reset --hard origin/master
113+ git cherry-pick $RELEASE_TAG
114+ git push origin $branch_name
115+ gh pr create --repo ${GITHUB_REPOSITORY} \
116+ --base master \
117+ --title " Update master docs for ${$REL_VERSION } release" \
118+ --body " Update master docs for ${$REL_VERSION } release"
119+ fi
120+
121+ echo " Done."
0 commit comments