Skip to content

Commit

Permalink
[3.4] Backport cherry-pick of etcd-io#14860: Trigger release in curre…
Browse files Browse the repository at this point in the history
…nt branch for github workflow case

Signed-off-by: ArkaSaha30 <[email protected]>
  • Loading branch information
ahrtr authored and ArkaSaha30 committed Mar 30, 2023
2 parents 2b189d8 + 01c0d8b commit 559ccdd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
Name-Email: [email protected]
Expire-Date: 0
EOF
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push 3.4.99
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push --in-place 3.4.99
26 changes: 21 additions & 5 deletions etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,16 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) {
return err
}

func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) bool {
func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) error {
authInfo, err := sws.ag.AuthInfoFromCtx(sws.gRPCStream.Context())
if err != nil {
return false
return err
}
if authInfo == nil {
// if auth is enabled, IsRangePermitted() can cause an error
authInfo = &auth.AuthInfo{}
}
return sws.ag.AuthStore().IsRangePermitted(authInfo, wcr.Key, wcr.RangeEnd) == nil
return sws.ag.AuthStore().IsRangePermitted(authInfo, wcr.Key, wcr.RangeEnd)
}

func (sws *serverWatchStream) recvLoop() error {
Expand Down Expand Up @@ -277,13 +277,29 @@ func (sws *serverWatchStream) recvLoop() error {
creq.RangeEnd = []byte{}
}

if !sws.isWatchPermitted(creq) {
err := sws.isWatchPermitted(creq)
if err != nil {
var cancelReason string
switch err {
case auth.ErrInvalidAuthToken:
cancelReason = rpctypes.ErrGRPCInvalidAuthToken.Error()
case auth.ErrAuthOldRevision:
cancelReason = rpctypes.ErrGRPCAuthOldRevision.Error()
case auth.ErrUserEmpty:
cancelReason = rpctypes.ErrGRPCUserEmpty.Error()
default:
if err != auth.ErrPermissionDenied {
sws.lg.Error("unexpected error code", zap.Error(err))
}
cancelReason = rpctypes.ErrGRPCPermissionDenied.Error()
}

wr := &pb.WatchResponse{
Header: sws.newResponseHeader(sws.watchStream.Rev()),
WatchId: clientv3.InvalidWatchID,
Canceled: true,
Created: true,
CancelReason: rpctypes.ErrGRPCPermissionDenied.Error(),
CancelReason: cancelReason,
}

select {
Expand Down
28 changes: 14 additions & 14 deletions scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ set -e
source ./scripts/test_lib.sh

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

if [ -z "$1" ]; then
echo "Usage: ${0} VERSION" >> /dev/stderr
Expand All @@ -16,18 +15,17 @@ fi
set -u

function setup_env {
local proj=${1}
local ver=${2}
local ver=${1}
local proj=${2}

if [ ! -d "${proj}" ]; then
log_callout "Cloning ${REPOSITORY}..."
git clone "${REPOSITORY}"
fi
if [ ! -d "${proj}" ]; then
run git clone "${REPOSITORY}"
fi

pushd "${proj}" >/dev/null
git fetch --all
git checkout "${ver}"
popd >/dev/null
pushd "${proj}" >/dev/null
run git fetch --all
run git checkout "${ver}"
popd >/dev/null
}


Expand Down Expand Up @@ -55,9 +53,11 @@ function package {
}

function main {
local proj="etcd"

mkdir -p release
cd release
setup_env "${PROJ}" "${VER}"
setup_env "${proj}" "${VER}"

tarcmd=tar
if [[ $(go env GOOS) == "darwin" ]]; then
Expand All @@ -83,7 +83,7 @@ function main {

TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
mkdir "${TARGET}"
package "${TARGET}" "${PROJ}"
package "${TARGET}" "${proj}"

if [ ${GOOS} == "linux" ]; then
${tarcmd} cfz "${TARGET}.tar.gz" "${TARGET}"
Expand Down
93 changes: 70 additions & 23 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ help() {
echo " flags:"
echo " --no-upload: skip gs://etcd binary artifact uploads."
echo " --no-docker-push: skip docker image pushes."
echo " --in-place: build binaries using current branch."
echo ""
}

Expand All @@ -34,7 +35,15 @@ main() {
fi
RELEASE_VERSION="v${VERSION}"
MINOR_VERSION=$(echo "${VERSION}" | cut -d. -f 1-2)
BRANCH="release-${MINOR_VERSION}"

if [ "${IN_PLACE}" == 1 ]; then
# Trigger release in current branch
REPOSITORY=$(pwd)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
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 @@ -53,12 +62,19 @@ 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" ] && [ "${IN_PLACE}" == 0 ]; then
mkdir -p "${reldir}"
cd "${reldir}"
git clone https://github.com/etcd-io/etcd.git --branch "${BRANCH}"
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
cd "${reldir}/etcd"

# mark local directory as root for test_lib scripts executions
set_root_dir

# If a release version tag already exists, use it.
log_callout "Checking tag: ${RELEASE_VERSION}"
Expand All @@ -70,7 +86,7 @@ main() {
fi

# Check go version.
log_callout "Checking go version"
log_callout "Check go version"
local go_version current_go_version
go_version="go$(grep go-version .github/workflows/tests.yaml | awk '{print $2}' | tr -d '"')"
current_go_version=$(go version | awk '{ print $3 }')
Expand All @@ -80,6 +96,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 @@ -112,8 +129,8 @@ main() {
fi

# Push the version change if it's not already been pushed.
if [ "$DRY_RUN" != "true" ] && [ "$(git rev-list --count "origin/${BRANCH}..${BRANCH}")" -gt 0 ]; then
read -p "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " -r confirm
if [ "${DRY_RUN}" != "true" ] && [ "$(git rev-list --count "origin/${BRANCH}..${BRANCH}")" -gt 0 ]; then
read -p "Push version bump up to ${VERSION} to '$(git remote get-url origin)' [y/N]? " -r confirm
[[ "${confirm,,}" == "y" ]] || exit 1
git push
fi
Expand All @@ -140,20 +157,38 @@ main() {
exit 1
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}" != "release-${MINOR_VERSION}" ]; then
log_error "Error: Git tag ${RELEASE_VERSION} should be on branch release-${MINOR_VERSION} but is on ${branch}"
exit 1
if [ "${IN_PLACE}" == 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

# Push the tag change if it's not already been pushed.
if [ "$DRY_RUN" != "true" ]; then
read -p "Push etcd ${RELEASE_VERSION} tag [y/N]? " -r confirm
[[ "${confirm,,}" == "y" ]] || exit 1
git push origin "tags/${RELEASE_VERSION}"
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)"
if [ "${tag}" != "${RELEASE_VERSION}" ]; then
log_error "Error: Expected HEAD to be tagged with ${RELEASE_VERSION}, but 'git describe --exact-match HEAD' reported: ${tag}"
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)"
if [[ "${diff}" != '' ]]; then
log_error "Error: Expected clean working tree, but 'git diff --stat' reported: ${diff}"
exit 1
fi
fi

# Build release.
Expand Down Expand Up @@ -185,8 +220,8 @@ main() {
fi

# Upload artifacts.
if [ "$DRY_RUN" = "true" ] || [ "${NO_UPLOAD}" == 1 ]; then
log_callout "Skipping artifact upload to gs://etcd. --no-upload flat is set or DRY_RUN is true."
if [ "${DRY_RUN}" == "true" ] || [ "${NO_UPLOAD}" == 1 ]; then
log_callout "Skipping artifact upload to gs://etcd. --no-upload flat is set."
else
read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " -r confirm
[[ "${confirm,,}" == "y" ]] || exit 1
Expand All @@ -197,8 +232,8 @@ main() {
fi

# Push images.
if [ "$DRY_RUN" = "true" ] || [ "${NO_DOCKER_PUSH}" == 1 ]; then
log_callout "Skipping docker push. --no-docker-push flat is set or DRY_RUN is true."
if [ "${DRY_RUN}" == "true" ] || [ "${NO_DOCKER_PUSH}" == 1 ]; then
log_callout "Skipping docker push. --no-docker-push flat is set."
else
read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " -r confirm
[[ "${confirm,,}" == "y" ]] || exit 1
Expand Down Expand Up @@ -261,6 +296,7 @@ main() {
POSITIONAL=()
NO_UPLOAD=0
NO_DOCKER_PUSH=0
IN_PLACE=0

while test $# -gt 0; do
case "$1" in
Expand All @@ -269,6 +305,10 @@ while test $# -gt 0; do
help
exit 0
;;
--in-place)
IN_PLACE=1
shift
;;
--no-upload)
NO_UPLOAD=1
shift
Expand All @@ -290,4 +330,11 @@ if [[ ! $# -eq 1 ]]; then
exit 1
fi

# Note that we shouldn't upload artifacts in --in-place mode, so it
# must be called with DRY_RUN=true
if [ "${DRY_RUN}" != "true" ] && [ "${IN_PLACE}" == 1 ]; then
log_error "--in-place should only be called with DRY_RUN=true"
exit 1
fi

main "$1"
8 changes: 7 additions & 1 deletion scripts/test_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ if [[ "$(go list)" != "${ROOT_MODULE}" ]]; then
exit 255
fi

function set_root_dir {
ETCD_ROOT_DIR=$(go list -f '{{.Dir}}' "${ROOT_MODULE}/v3")
}

set_root_dir

#### Convenient IO methods #####

COLOR_RED='\033[0;31m'
Expand Down Expand Up @@ -51,4 +57,4 @@ function log_info {
>&2 echo -n -e "${COLOR_NONE}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}
}

0 comments on commit 559ccdd

Please sign in to comment.