@@ -23,14 +23,29 @@ set -o errexit
23
23
set -o nounset
24
24
set -o pipefail
25
25
26
+ declare -a RELEASE_TYPES=(" major" " minor" " patch" )
27
+ upstream_master=" master"
28
+ origin_master=" master"
29
+
26
30
if [[ -z " ${1-} " ]]; then
27
31
echo " Usage: $0 TAG"
28
32
echo " TAG: the tag to build or release, e.g. api/v1.2.3"
29
33
exit 1
30
34
fi
31
35
36
+ if [[ -z " ${2-} " ]]; then
37
+ echo " Release type not specified, using default value: patch"
38
+ release_type=" patch"
39
+ elif [[ ! " ${RELEASE_TYPES[*]} " =~ " ${2} " ]]; then
40
+ echo " Unsupported release type, only input these values: major, minor, patch."
41
+ exit 1
42
+ fi
43
+
32
44
git_tag=$1
45
+ release_type=$2
46
+
33
47
echo " release tag: $git_tag "
48
+ echo " release type: $release_type "
34
49
35
50
# Build the release binaries for every OS/arch combination.
36
51
# It builds compressed artifacts on $release_dir.
@@ -81,22 +96,39 @@ function build_kustomize_binary {
81
96
}
82
97
83
98
function create_release {
99
+ source ./releasing/helpers.sh
100
+
84
101
git_tag=$1
85
102
86
103
# Take everything before the last slash.
87
104
# This is expected to match $module.
88
105
module=${git_tag%/* }
106
+ module_slugified=$( echo $module | iconv -t ascii//TRANSLIT | sed -E -e ' s/[^[:alnum:]]+/-/g' -e ' s/^-+|-+$//g' | tr ' [:upper:]' ' [:lower:]' )
89
107
90
108
# Take everything after the last slash.
91
109
version=${git_tag##*/ }
92
110
111
+ determineNextVersion $@
112
+
113
+ release_branch=" release-${module} /${nextVersion} "
114
+
115
+ # Create release branch release-{module}/{version}
116
+ echo " Creating release branch $release_branch ..."
117
+ git fetch --tags upstream $upstream_master
118
+ git branch $release_branch $origin_master
119
+ git commit -a -m " create release branch $release_branch " || true
120
+ git push -f origin $release_branch
121
+
93
122
# Generate the changelog for this release
94
123
# using the last two tags for the module
95
124
changelog_file=$( mktemp)
96
- ./releasing/compile-changelog.sh " $module " " $git_tag " " $changelog_file "
125
+ ./releasing/compile-changelog.sh " $module " " HEAD " " $changelog_file "
97
126
98
127
additional_release_artifacts_arg=" "
99
128
129
+ # Trigger workflow for respective modeule release
130
+ gh workflow run " release-${module_slugified} .yml" -f " release_type=${release_type} " -f " release_branch=${release_branch} "
131
+
100
132
# build `kustomize` binary
101
133
if [[ " $module " == " kustomize" ]]; then
102
134
release_artifact_dir=$( mktemp -d)
@@ -122,6 +154,27 @@ function create_release {
122
154
--notes-file " $changelog_file "
123
155
}
124
156
157
+ function determineNextVersion {
158
+ currentTag=$( git tag --list " ${module} *" --sort=-creatordate | head -n1)
159
+ currentVersion=$( echo ${currentTag##*/ } | cut -d' v' -f2)
160
+ majorVer=$( echo $currentVersion | cut -d' .' -f1)
161
+ minorVer=$( echo $currentVersion | cut -d' .' -f2)
162
+ patchVer=$( echo $currentVersion | cut -d' .' -f3)
163
+
164
+ if [[ ${release_type} == " major" ]]; then
165
+ majorVer=" $(( $majorVer + 1 )) "
166
+ elif [[ ${release_type} == " minor" ]]; then
167
+ minorVer=" $(( $minorVer + 1 )) "
168
+ elif [[ ${release_type} == " patch" ]]; then
169
+ patchVer=" $(( $patchVer + 1 )) "
170
+ else
171
+ echo " Error: release_type not supported. Available values 'major', 'minor', 'patch'"
172
+ exit 1
173
+ fi
174
+
175
+ nextVersion=" $majorVer .$minorVer .$patchVer "
176
+ return
177
+ }
125
178
126
179
# # create release
127
180
create_release " $git_tag "
0 commit comments