@@ -41,6 +41,7 @@ help() {
41
41
echo " flags:"
42
42
echo " --no-upload: skip gs://etcd binary artifact uploads."
43
43
echo " --no-docker-push: skip docker image pushes."
44
+ echo " --in-place: build binaries using current branch."
44
45
echo " "
45
46
echo " One can perform a (dry-run) test release from any (uncommitted) branch using:"
46
47
echo " DRY_RUN=true REPOSITORY=\` pwd\` BRANCH='local-branch-name' ./scripts/release 3.5.0-foobar.2"
@@ -54,8 +55,15 @@ main() {
54
55
fi
55
56
RELEASE_VERSION=" v${VERSION} "
56
57
MINOR_VERSION=$( echo " ${VERSION} " | cut -d. -f 1-2)
57
- BRANCH=${BRANCH:- " release-${MINOR_VERSION} " }
58
- REPOSITORY=${REPOSITORY:- " https://github.com/etcd-io/etcd.git" }
58
+
59
+ if [ " ${IN_PLACE} " == 1 ]; then
60
+ # Trigger release in current branch
61
+ REPOSITORY=$( pwd)
62
+ BRANCH=$( git rev-parse --abbrev-ref HEAD)
63
+ else
64
+ REPOSITORY=${REPOSITORY:- " https://github.com/etcd-io/etcd.git" }
65
+ BRANCH=${BRANCH:- " release-${MINOR_VERSION} " }
66
+ fi
59
67
60
68
log_warning " DRY_RUN=${DRY_RUN} "
61
69
log_callout " RELEASE_VERSION=${RELEASE_VERSION} "
@@ -78,19 +86,20 @@ main() {
78
86
# Set up release directory.
79
87
local reldir=" /tmp/etcd-release-${VERSION} "
80
88
log_callout " Preparing temporary directory: ${reldir} "
81
- if [ ! -d " ${reldir} /etcd" ]; then
89
+ if [ ! -d " ${reldir} /etcd" ] && [ " ${IN_PLACE} " == 0 ] ; then
82
90
mkdir -p " ${reldir} "
83
91
cd " ${reldir} "
84
92
run git clone " ${REPOSITORY} " --branch " ${BRANCH} "
93
+ run cd " ${reldir} /etcd" || exit 2
94
+ run git checkout " ${BRANCH} " || exit 2
95
+ run git pull origin
96
+
97
+ git_assert_branch_in_sync || exit 2
85
98
fi
86
- run cd " ${reldir} /etcd " || exit 2
99
+
87
100
# mark local directory as root for test_lib scripts executions
88
101
set_root_dir
89
102
90
- run git checkout " ${BRANCH} " || exit 2
91
- run git pull origin
92
- git_assert_branch_in_sync || exit 2
93
-
94
103
# If a release version tag already exists, use it.
95
104
local remote_tag_exists
96
105
remote_tag_exists=$( run git ls-remote origin " refs/tags/${RELEASE_VERSION} " | grep -c " ${RELEASE_VERSION} " || true)
@@ -101,6 +110,7 @@ main() {
101
110
fi
102
111
103
112
# Check go version.
113
+ log_callout " Check go version"
104
114
local go_version current_go_version
105
115
go_version=" go$( grep go-version .github/workflows/build.yaml | awk ' {print $2}' | tr -d ' "' ) "
106
116
current_go_version=$( go version | awk ' { print $3 }' )
@@ -110,6 +120,7 @@ main() {
110
120
fi
111
121
112
122
# If the release tag does not already exist remotely, create it.
123
+ log_callout " Create tag if not present"
113
124
if [ " ${remote_tag_exists} " -eq 0 ]; then
114
125
# Bump version/version.go to release version.
115
126
local source_version
@@ -148,7 +159,7 @@ main() {
148
159
fi
149
160
150
161
# Push the version change if it's not already been pushed.
151
- if [ " $DRY_RUN " != " true" ] && [ " $( git rev-list --count " origin/${BRANCH} ..${BRANCH} " ) " -gt 0 ]; then
162
+ if [ " ${ DRY_RUN} " != " true" ] && [ " $( git rev-list --count " origin/${BRANCH} ..${BRANCH} " ) " -gt 0 ]; then
152
163
read -p " Push version bump up to ${VERSION} to '$( git remote get-url origin) ' [y/N]? " -r confirm
153
164
[[ " ${confirm,,} " == " y" ]] || exit 1
154
165
maybe_run git push
@@ -162,15 +173,23 @@ main() {
162
173
REMOTE_REPO=" origin" push_mod_tags_cmd
163
174
fi
164
175
165
- # Verify the version tag is on the right branch
166
- # shellcheck disable=SC2155
167
- local branch=$( git for-each-ref --contains " ${RELEASE_VERSION} " --format=" %(refname)" ' refs/heads' | cut -d ' /' -f 3)
168
- if [ " ${branch} " != " ${BRANCH} " ]; then
169
- log_error " Error: Git tag ${RELEASE_VERSION} should be on branch '${BRANCH} ' but is on '${branch} '"
170
- exit 1
176
+ if [ " ${IN_PLACE} " == 0 ]; then
177
+ # Tried with `local branch=$(git branch -a --contains tags/"${RELEASE_VERSION}")`
178
+ # so as to work with both current branch and main/release-3.X.
179
+ # But got error below on current branch mode,
180
+ # Error: Git tag v3.6.99 should be on branch '* (HEAD detached at pull/14860/merge)' but is on '* (HEAD detached from pull/14860/merge)'
181
+ #
182
+ # Verify the version tag is on the right branch
183
+ # shellcheck disable=SC2155
184
+ local branch=$( git for-each-ref --contains " ${RELEASE_VERSION} " --format=" %(refname)" ' refs/heads' | cut -d ' /' -f 3)
185
+ if [ " ${branch} " != " ${BRANCH} " ]; then
186
+ log_error " Error: Git tag ${RELEASE_VERSION} should be on branch '${BRANCH} ' but is on '${branch} '"
187
+ exit 1
188
+ fi
171
189
fi
172
190
fi
173
191
192
+ log_callout " Verify the latest commit has the version tag"
174
193
# Verify the latest commit has the version tag
175
194
# shellcheck disable=SC2155
176
195
local tag=" $( git describe --exact-match HEAD) "
@@ -179,6 +198,7 @@ main() {
179
198
exit 1
180
199
fi
181
200
201
+ log_callout " Verify the work space is clean"
182
202
# Verify the clean working tree
183
203
# shellcheck disable=SC2155
184
204
local diff=" $( git diff HEAD --stat) "
@@ -215,7 +235,7 @@ main() {
215
235
fi
216
236
217
237
# Upload artifacts.
218
- if [ " ${NO_UPLOAD} " == 1 ]; then
238
+ if [ " ${DRY_RUN} " == " true " ] || [ " ${ NO_UPLOAD}" == 1 ]; then
219
239
log_callout " Skipping artifact upload to gs://etcd. --no-upload flat is set."
220
240
else
221
241
read -p " Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " -r confirm
@@ -227,7 +247,7 @@ main() {
227
247
fi
228
248
229
249
# Push images.
230
- if [ " ${NO_DOCKER_PUSH} " == 1 ]; then
250
+ if [ " ${DRY_RUN} " == " true " ] || [ " ${ NO_DOCKER_PUSH}" == 1 ]; then
231
251
log_callout " Skipping docker push. --no-docker-push flat is set."
232
252
else
233
253
read -p " Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " -r confirm
@@ -308,6 +328,7 @@ main() {
308
328
POSITIONAL=()
309
329
NO_UPLOAD=0
310
330
NO_DOCKER_PUSH=0
331
+ IN_PLACE=0
311
332
312
333
while test $# -gt 0; do
313
334
case " $1 " in
@@ -316,6 +337,10 @@ while test $# -gt 0; do
316
337
help
317
338
exit 0
318
339
;;
340
+ --in-place)
341
+ IN_PLACE=1
342
+ shift
343
+ ;;
319
344
--no-upload)
320
345
NO_UPLOAD=1
321
346
shift
@@ -337,4 +362,11 @@ if [[ ! $# -eq 1 ]]; then
337
362
exit 1
338
363
fi
339
364
365
+ # Note that we shouldn't upload artifacts in --in-place mode, so it
366
+ # must be called with DRY_RUN=true
367
+ if [ " ${DRY_RUN} " != " true" ] && [ " ${IN_PLACE} " == 1 ]; then
368
+ log_error " --in-place should only be called with DRY_RUN=true"
369
+ exit 1
370
+ fi
371
+
340
372
main " $1 "
0 commit comments