Skip to content

Commit

Permalink
Merge pull request #12452 from ptabor/20201104-release-mod-scripts
Browse files Browse the repository at this point in the history
Release scripts for modules
  • Loading branch information
gyuho committed Nov 14, 2020
2 parents dc586a5 + eeafcef commit 1b8d2b1
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 44 deletions.
4 changes: 2 additions & 2 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.15
require (
github.com/json-iterator/go v1.1.10
github.com/modern-go/reflect2 v1.0.1
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
)

replace (
Expand Down
4 changes: 2 additions & 2 deletions client/v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/google/uuid v1.1.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/prometheus/client_golang v1.5.1
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
go.uber.org/zap v1.16.0
google.golang.org/grpc v1.29.1
sigs.k8s.io/yaml v1.2.0
Expand Down
12 changes: 6 additions & 6 deletions etcdctl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ require (
github.com/spf13/pflag v1.0.5
github.com/urfave/cli v1.22.4
go.etcd.io/bbolt v1.3.5
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v2 v2.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/raft/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/server/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/client/v2 v2.305.0-pre
go.etcd.io/etcd/client/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
go.etcd.io/etcd/raft/v3 v3.5.0-pre
go.etcd.io/etcd/server/v3 v3.5.0-pre
go.uber.org/zap v1.16.0
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
google.golang.org/grpc v1.29.1
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ require (
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/spf13/cobra v1.1.1
go.etcd.io/bbolt v1.3.5
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v2 v2.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/raft/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/server/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/tests/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/client/v2 v2.305.0-pre
go.etcd.io/etcd/client/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
go.etcd.io/etcd/raft/v3 v3.5.0-pre
go.etcd.io/etcd/server/v3 v3.5.0-pre
go.etcd.io/etcd/tests/v3 v3.5.0-pre
go.uber.org/zap v1.16.0
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
google.golang.org/grpc v1.29.1
Expand Down
2 changes: 1 addition & 1 deletion raft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.5
github.com/pkg/errors v0.9.1 // indirect
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
)

// Bad imports are sometimes causing attempts to pull that code.
Expand Down
124 changes: 124 additions & 0 deletions scripts/release_mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env bash

# Examples:

# Edit go.mod files such that all etcd modules are pointing on given version:
#
# % DRY_RUN=false TARGET_VERSION="v3.5.13" ./scripts/release_mod.sh update_versions

# Tag latest commit with current version number for all the modules and push upstream:
#
# % DRY_RUN=false REMOTE_REPO="origin" ./scripts/release_mod.sh push_mod_tags

set -e

DRY_RUN=${DRY_RUN:-true}

if ! [[ "$0" =~ scripts/release_mod.sh ]]; then
echo "must be run from repository root"
exit 255
fi

source ./scripts/test_lib.sh

# _cmd prints help message
function _cmd() {
log_error "Command required: ${0} [cmd]"
log_info "Available commands:"
log_info " - update_versions - Updates all cross-module versions to \${TARGET_VERSION} in the local client."
log_info " - push_mod_tags - Tags HEAD with all modules versions tags and pushes it to \${REMOTE_REPO}."
}

# maybe_run [cmd...] runs given command depending on the DRY_RUN flag.
function maybe_run() {
if ${DRY_RUN}; then
log_warning -e "# DRY_RUN:\n % ${*}"
else
run "${@}"
fi
}

# update_module_version [v2version] [v3version]
# Updates versions of cross-references in all internal references in current module.
function update_module_version() {
local v3version="${1}"
local v2version="${2}"
local modules
modules=$(run go list -f '{{if not .Main}}{{if not .Indirect}}{{.Path}}{{end}}{{end}}' -m all)

v3deps=$(echo "${modules}" | grep -E "${REPO}/.*/v3")
for dep in ${v3deps}; do
maybe_run go mod edit -require "${dep}@${v3version}"
done

v2deps=$(echo "${modules}" | grep -E "${REPO}/.*/v2")
for dep in ${v2deps}; do
maybe_run go mod edit -require "${dep}@${v2version}"
done
}

# Updates all cross-module versions to ${TARGET_VERSION} in local client.
function update_versions_cmd() {
assert_no_git_modifications || return 2

if [ -z "${TARGET_VERSION}" ]; then
log_error "TARGET_VERSION environment variable not set. Set it to e.g. v3.5.10-alpha.0"
return 2
fi

local v3version="${TARGET_VERSION}"
local v2version
# converts e.g. v3.5.0-alpha.0 --> v2.305.0-alpha.0
# shellcheck disable=SC2001
v2version="$(echo "${TARGET_VERSION}" | sed 's|^v3.\([0-9]*\).|v2.30\1.|g')"

log_info "DRY_RUN : ${DRY_RUN}"
log_info "TARGET_VERSION: ${TARGET_VERSION}"
log_info ""
log_info "v3version: ${v3version}"
log_info "v2version: ${v2version}"

run_for_modules update_module_version "${v3version}" "${v2version}"
}

function push_mod_tags_cmd {
assert_no_git_modifications || return 2

if [ -z "${REMOTE_REPO}" ]; then
log_error "REMOTE_REPO environment variable not set"
return 2
fi
log_info "REMOTE_REPO: ${REMOTE_REPO}"

# Any module ccan be used for this
local master_version
master_version=$(go list -f '{{.Version}}' -m "${REPO}/api/v3")
local tags=()

for module in $(modules); do
local version
version=$(go list -f '{{.Version}}' -m "${module}")
local path
path=$(go list -f '{{.Path}}' -m "${module}")
local subdir="${path//${REPO}\//}"
local tag
if [ -z "${version}" ]; then
tag="${master_version}"
version="${master_version}"
else
tag="${subdir///v[23]/}/${version}"
fi

log_info "Tags for: ${module} version:${version} tag:${tag}"
maybe_run git tag -f "${tag}"
tags=("${tags[@]}" "${tag}")
done
maybe_run git push -f "${REMOTE_REPO}" "${tags[@]}"
}

"${1}_cmd"

if "${DRY_RUN}"; then
log_info
log_warning "WARNING: It was a DRY_RUN. No files were modified."
fi
54 changes: 40 additions & 14 deletions scripts/test_lib.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env bash

if [[ "$(go list)" != "go.etcd.io/etcd/v3" ]]; then
echo "must be run from 'go.etcd.io/etcd/v3' module directory"
REPO="go.etcd.io/etcd"

if [[ "$(go list)" != "${REPO}/v3" ]]; then
echo "must be run from '${REPO}/v3' module directory"
exit 255
fi

ETCD_ROOT_DIR=$(go list -f '{{.Dir}}' "go.etcd.io/etcd/v3")
ETCD_ROOT_DIR=$(go list -f '{{.Dir}}' "${REPO}/v3")

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

Expand Down Expand Up @@ -48,6 +50,12 @@ function log_success {
>&2 echo -n -e "${COLOR_NONE}"
}

function log_info {
>&2 echo -n -e "${COLOR_NONE}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}

# From http://stackoverflow.com/a/12498485
function relativePath {
# both $1 and $2 are absolute paths beginning with /
Expand Down Expand Up @@ -105,6 +113,11 @@ function pkgs_in_module {
go list -mod=mod "${1:-./...}";
}

# Prints subdirectory (from the repo root) for the current module.
function module_subdir {
relativePath "${ETCD_ROOT_DIR}" "${PWD}"
}

#### Running actions against multiple modules ####

# run [command...] - runs given command, printing it first and
Expand All @@ -114,11 +127,11 @@ function pkgs_in_module {
function run {
local rpath
local command
rpath=$(relativePath "${ETCD_ROOT_DIR}" "${PWD}")
rpath=$(module_subdir)
# Quoting all components as the commands are fully copy-parsable:
command=("${@}")
command=("${command[@]@Q}")
if [ "${rpath}" != "." ]; then
if [[ "${rpath}" != "." && "${rpath}" != "" ]]; then
repro="(cd ${rpath} && ${command[*]})"
else
repro="${command[*]}"
Expand Down Expand Up @@ -147,15 +160,15 @@ function run_for_module {

function modules() {
modules=(
go.etcd.io/etcd/api/v3
go.etcd.io/etcd/pkg/v3
go.etcd.io/etcd/raft/v3
go.etcd.io/etcd/client/v2
go.etcd.io/etcd/client/v3
go.etcd.io/etcd/server/v3
go.etcd.io/etcd/etcdctl/v3
go.etcd.io/etcd/tests/v3
go.etcd.io/etcd/v3)
"${REPO}/api/v3"
"${REPO}/pkg/v3"
"${REPO}/raft/v3"
"${REPO}/client/v2"
"${REPO}/client/v3"
"${REPO}/server/v3"
"${REPO}/etcdctl/v3"
"${REPO}/tests/v3"
"${REPO}/v3")
echo "${modules[@]}"
}

Expand Down Expand Up @@ -313,3 +326,16 @@ function run_go_tool {
run "${cmdbin}" "$@" || return 2
}

# assert_no_git_modifications fails if there are any uncommited changes.
function assert_no_git_modifications {
log_callout "Making sure everything is committed."
if ! git diff --cached --exit-code; then
log_error "Found staged by uncommited changes. Do commit/stash your changes first."
return 2
fi
if ! git diff --exit-code; then
log_error "Found unstaged and uncommited changes. Do commit/stash your changes first."
return 2
fi
}

10 changes: 5 additions & 5 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2
go.etcd.io/bbolt v1.3.5
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v2 v2.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/raft/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/client/v2 v2.305.0-pre
go.etcd.io/etcd/client/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
go.etcd.io/etcd/raft/v3 v3.5.0-pre
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
Expand Down
14 changes: 7 additions & 7 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
go.etcd.io/bbolt v1.3.5
go.etcd.io/etcd/api/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v2 v2.0.0-00010101000000-000000000000
go.etcd.io/etcd/client/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/etcdctl/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/pkg/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/raft/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/server/v3 v3.0.0-00010101000000-000000000000
go.etcd.io/etcd/api/v3 v3.5.0-pre
go.etcd.io/etcd/client/v2 v2.305.0-pre
go.etcd.io/etcd/client/v3 v3.5.0-pre
go.etcd.io/etcd/etcdctl/v3 v3.5.0-pre
go.etcd.io/etcd/pkg/v3 v3.5.0-pre
go.etcd.io/etcd/raft/v3 v3.5.0-pre
go.etcd.io/etcd/server/v3 v3.5.0-pre
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
Expand Down

0 comments on commit 1b8d2b1

Please sign in to comment.