Skip to content

Commit ee9db72

Browse files
authored
Merge pull request #14860 from ahrtr/fix_release_20221126
Trigger release in current branch for github workflow case
2 parents 638d0a0 + 5d78d6d commit ee9db72

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
Name-Email: [email protected]
2323
Expire-Date: 0
2424
EOF
25-
DRY_RUN=true BRANCH=main ./scripts/release.sh --no-upload --no-docker-push 3.6.99
25+
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push --in-place 3.6.99

scripts/build-binary.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ source ./scripts/test_lib.sh
77
VER=$1
88
REPOSITORY="${REPOSITORY:-git@github.com:etcd-io/etcd.git}"
99

10-
1110
if [ -z "$1" ]; then
1211
echo "Usage: ${0} VERSION" >> /dev/stderr
1312
exit 255
@@ -25,9 +24,7 @@ function setup_env {
2524

2625
pushd "${proj}" >/dev/null
2726
run git fetch --all
28-
git_assert_branch_in_sync || exit 2
2927
run git checkout "${ver}"
30-
git_assert_branch_in_sync || exit 2
3128
popd >/dev/null
3229
}
3330

scripts/release.sh

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ help() {
4141
echo " flags:"
4242
echo " --no-upload: skip gs://etcd binary artifact uploads."
4343
echo " --no-docker-push: skip docker image pushes."
44+
echo " --in-place: build binaries using current branch."
4445
echo ""
4546
echo "One can perform a (dry-run) test release from any (uncommitted) branch using:"
4647
echo " DRY_RUN=true REPOSITORY=\`pwd\` BRANCH='local-branch-name' ./scripts/release 3.5.0-foobar.2"
@@ -54,8 +55,15 @@ main() {
5455
fi
5556
RELEASE_VERSION="v${VERSION}"
5657
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
5967

6068
log_warning "DRY_RUN=${DRY_RUN}"
6169
log_callout "RELEASE_VERSION=${RELEASE_VERSION}"
@@ -78,19 +86,20 @@ main() {
7886
# Set up release directory.
7987
local reldir="/tmp/etcd-release-${VERSION}"
8088
log_callout "Preparing temporary directory: ${reldir}"
81-
if [ ! -d "${reldir}/etcd" ]; then
89+
if [ ! -d "${reldir}/etcd" ] && [ "${IN_PLACE}" == 0 ]; then
8290
mkdir -p "${reldir}"
8391
cd "${reldir}"
8492
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
8598
fi
86-
run cd "${reldir}/etcd" || exit 2
99+
87100
# mark local directory as root for test_lib scripts executions
88101
set_root_dir
89102

90-
run git checkout "${BRANCH}" || exit 2
91-
run git pull origin
92-
git_assert_branch_in_sync || exit 2
93-
94103
# If a release version tag already exists, use it.
95104
local remote_tag_exists
96105
remote_tag_exists=$(run git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}" || true)
@@ -101,6 +110,7 @@ main() {
101110
fi
102111

103112
# Check go version.
113+
log_callout "Check go version"
104114
local go_version current_go_version
105115
go_version="go$(grep go-version .github/workflows/build.yaml | awk '{print $2}' | tr -d '"')"
106116
current_go_version=$(go version | awk '{ print $3 }')
@@ -110,6 +120,7 @@ main() {
110120
fi
111121

112122
# If the release tag does not already exist remotely, create it.
123+
log_callout "Create tag if not present"
113124
if [ "${remote_tag_exists}" -eq 0 ]; then
114125
# Bump version/version.go to release version.
115126
local source_version
@@ -148,7 +159,7 @@ main() {
148159
fi
149160

150161
# 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
152163
read -p "Push version bump up to ${VERSION} to '$(git remote get-url origin)' [y/N]? " -r confirm
153164
[[ "${confirm,,}" == "y" ]] || exit 1
154165
maybe_run git push
@@ -162,15 +173,23 @@ main() {
162173
REMOTE_REPO="origin" push_mod_tags_cmd
163174
fi
164175

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
171189
fi
172190
fi
173191

192+
log_callout "Verify the latest commit has the version tag"
174193
# Verify the latest commit has the version tag
175194
# shellcheck disable=SC2155
176195
local tag="$(git describe --exact-match HEAD)"
@@ -179,6 +198,7 @@ main() {
179198
exit 1
180199
fi
181200

201+
log_callout "Verify the work space is clean"
182202
# Verify the clean working tree
183203
# shellcheck disable=SC2155
184204
local diff="$(git diff HEAD --stat)"
@@ -215,7 +235,7 @@ main() {
215235
fi
216236

217237
# Upload artifacts.
218-
if [ "${NO_UPLOAD}" == 1 ]; then
238+
if [ "${DRY_RUN}" == "true" ] || [ "${NO_UPLOAD}" == 1 ]; then
219239
log_callout "Skipping artifact upload to gs://etcd. --no-upload flat is set."
220240
else
221241
read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " -r confirm
@@ -227,7 +247,7 @@ main() {
227247
fi
228248

229249
# Push images.
230-
if [ "${NO_DOCKER_PUSH}" == 1 ]; then
250+
if [ "${DRY_RUN}" == "true" ] || [ "${NO_DOCKER_PUSH}" == 1 ]; then
231251
log_callout "Skipping docker push. --no-docker-push flat is set."
232252
else
233253
read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " -r confirm
@@ -308,6 +328,7 @@ main() {
308328
POSITIONAL=()
309329
NO_UPLOAD=0
310330
NO_DOCKER_PUSH=0
331+
IN_PLACE=0
311332

312333
while test $# -gt 0; do
313334
case "$1" in
@@ -316,6 +337,10 @@ while test $# -gt 0; do
316337
help
317338
exit 0
318339
;;
340+
--in-place)
341+
IN_PLACE=1
342+
shift
343+
;;
319344
--no-upload)
320345
NO_UPLOAD=1
321346
shift
@@ -337,4 +362,11 @@ if [[ ! $# -eq 1 ]]; then
337362
exit 1
338363
fi
339364

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+
340372
main "$1"

scripts/test_lib.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,16 @@ function assert_no_git_modifications {
410410
# - no differencing commits in relation to the origin/$branch
411411
function git_assert_branch_in_sync {
412412
local branch
413-
branch=$(run git rev-parse --abbrev-ref HEAD)
414413
# TODO: When git 2.22 popular, change to:
415414
# branch=$(git branch --show-current)
415+
branch=$(run git rev-parse --abbrev-ref HEAD)
416+
log_callout "Verify the current branch '${branch}' is clean"
416417
if [[ $(run git status --porcelain --untracked-files=no) ]]; then
417418
log_error "The workspace in '$(pwd)' for branch: ${branch} has uncommitted changes"
418419
log_error "Consider cleaning up / renaming this directory or (cd $(pwd) && git reset --hard)"
419420
return 2
420421
fi
422+
log_callout "Verify the current branch '${branch}' is in sync with the 'origin/${branch}'"
421423
if [ -n "${branch}" ]; then
422424
ref_local=$(run git rev-parse "${branch}")
423425
ref_origin=$(run git rev-parse "origin/${branch}")

0 commit comments

Comments
 (0)