Skip to content

Commit

Permalink
release: support kick off release in current branch
Browse files Browse the repository at this point in the history
When triggering release process in github workflow, then always
run it in current branch, so that any changes in current branch
are included.

When manually triggering release, always pull remote repo and
checkout main branch.

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Nov 26, 2022
1 parent cdb9b8b commit bef29e3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
Name-Email: [email protected]
Expire-Date: 0
EOF
DRY_RUN=true BRANCH=main ./scripts/release.sh --no-upload --no-docker-push 3.6.99
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push --current-branch 3.6.99
16 changes: 9 additions & 7 deletions scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source ./scripts/test_lib.sh

VER=$1
REPOSITORY="${REPOSITORY:-git@github.com:etcd-io/etcd.git}"

CURRENT_BRANCH=${CURRENT_BRANCH:-0}

if [ -z "$1" ]; then
echo "Usage: ${0} VERSION" >> /dev/stderr
Expand All @@ -23,12 +23,14 @@ function setup_env {
run git clone "${REPOSITORY}"
fi

pushd "${proj}" >/dev/null
run git fetch --all
git_assert_branch_in_sync || exit 2
run git checkout "${ver}"
git_assert_branch_in_sync || exit 2
popd >/dev/null
if [ "${CURRENT_BRANCH}" == 0 ]; then
pushd "${proj}" >/dev/null
run git fetch --all
git_assert_branch_in_sync || exit 2
run git checkout "${ver}"
git_assert_branch_in_sync || exit 2
popd >/dev/null
fi
}


Expand Down
3 changes: 2 additions & 1 deletion scripts/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -e
source ./scripts/test_lib.sh

VERSION=$1
CURRENT_BRANCH=${CURRENT_BRANCH:-0}
if [ -z "${VERSION}" ]; then
echo "Usage: ${0} VERSION" >> /dev/stderr
exit 255
Expand All @@ -22,7 +23,7 @@ ETCD_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

pushd "${ETCD_ROOT}" >/dev/null
log_callout "Building etcd binary..."
./scripts/build-binary.sh "${VERSION}"
CURRENT_BRANCH=${CURRENT_BRANCH} ./scripts/build-binary.sh "${VERSION}"

for TARGET_ARCH in "amd64" "arm64" "ppc64le" "s390x"; do
log_callout "Building ${TARGET_ARCH} docker image..."
Expand Down
55 changes: 40 additions & 15 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ main() {
fi
RELEASE_VERSION="v${VERSION}"
MINOR_VERSION=$(echo "${VERSION}" | cut -d. -f 1-2)
BRANCH=${BRANCH:-"release-${MINOR_VERSION}"}
REPOSITORY=${REPOSITORY:-"https://github.com/etcd-io/etcd.git"}


if [ "${CURRENT_BRANCH}" == 1 ]; then
# Trigger release in current branch, used in github workflow
REPOSITORY=$(pwd)
BRANCH=$(git branch)
else
REPOSITORY=${REPOSITORY:-"https://github.com/etcd-io/etcd.git"}
BRANCH=${BRANCH:-"release-${MINOR_VERSION}"}
fi

log_warning "DRY_RUN=${DRY_RUN}"
log_callout "RELEASE_VERSION=${RELEASE_VERSION}"
Expand All @@ -78,19 +86,20 @@ main() {
# Set up release directory.
local reldir="/tmp/etcd-release-${VERSION}"
log_callout "Preparing temporary directory: ${reldir}"
if [ ! -d "${reldir}/etcd" ]; then
if [ ! -d "${reldir}/etcd" ] && [ "${CURRENT_BRANCH}" == 0 ]; then
mkdir -p "${reldir}"
cd "${reldir}"
run git clone "${REPOSITORY}" --branch "${BRANCH}"
run cd "${reldir}/etcd" || exit 2
run git checkout "${BRANCH}" || exit 2
run git pull origin

git_assert_branch_in_sync || exit 2
fi
run cd "${reldir}/etcd" || exit 2

# mark local directory as root for test_lib scripts executions
set_root_dir

run git checkout "${BRANCH}" || exit 2
run git pull origin
git_assert_branch_in_sync || exit 2

# If a release version tag already exists, use it.
local remote_tag_exists
remote_tag_exists=$(run git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}" || true)
Expand All @@ -101,6 +110,7 @@ main() {
fi

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

# If the release tag does not already exist remotely, create it.
log_callout "Create tag if not present"
if [ "${remote_tag_exists}" -eq 0 ]; then
# Bump version/version.go to release version.
local source_version
Expand Down Expand Up @@ -162,15 +173,23 @@ main() {
REMOTE_REPO="origin" push_mod_tags_cmd
fi

# Verify the version tag is on the right branch
# shellcheck disable=SC2155
local branch=$(git for-each-ref --contains "${RELEASE_VERSION}" --format="%(refname)" 'refs/heads' | cut -d '/' -f 3)
if [ "${branch}" != "${BRANCH}" ]; then
log_error "Error: Git tag ${RELEASE_VERSION} should be on branch '${BRANCH}' but is on '${branch}'"
exit 1
if [ "${CURRENT_BRANCH}" == 0 ]; then
# Tried with `local branch=$(git branch -a --contains tags/"${RELEASE_VERSION}")`
# so as to work with both current branch and main/release-3.X.
# But got error below on current branch mode,
# 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)'
#
# Verify the version tag is on the right branch
# shellcheck disable=SC2155
local branch=$(git for-each-ref --contains "${RELEASE_VERSION}" --format="%(refname)" 'refs/heads' | cut -d '/' -f 3)
if [ "${branch}" != "${BRANCH}" ]; then
log_error "Error: Git tag ${RELEASE_VERSION} should be on branch '${BRANCH}' but is on '${branch}'"
exit 1
fi
fi
fi

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

log_callout "Verify the work space is clean"
# Verify the clean working tree
# shellcheck disable=SC2155
local diff="$(git diff HEAD --stat)"
Expand All @@ -193,7 +213,7 @@ main() {
log_warning "Skipping release build step. /release directory already exists."
else
log_callout "Building release..."
REPOSITORY=$(pwd) ./scripts/build-release.sh "${RELEASE_VERSION}"
REPOSITORY=$(pwd) CURRENT_BRANCH=${CURRENT_BRANCH} ./scripts/build-release.sh "${RELEASE_VERSION}"
fi

# Sanity checks.
Expand Down Expand Up @@ -308,6 +328,7 @@ main() {
POSITIONAL=()
NO_UPLOAD=0
NO_DOCKER_PUSH=0
CURRENT_BRANCH=0

while test $# -gt 0; do
case "$1" in
Expand All @@ -316,6 +337,10 @@ while test $# -gt 0; do
help
exit 0
;;
--current-branch)
CURRENT_BRANCH=1
shift
;;
--no-upload)
NO_UPLOAD=1
shift
Expand Down

0 comments on commit bef29e3

Please sign in to comment.