.*: sync go toolchain version and add ability to verify versions
This commit adds a script to sync the version present in .go-version across all go.mod files as the toolchain directive. As part of that, this commit also modifies go.mod files that did not have synced toolchain directives. Additionally, this also adds a script to verify all toolchain and go directives against the version present in .go-version as follows: (1) The go directive <= version in .go-version (2) The toolchain directive == version in .go-version This script runs as part of the `make verify` target, making it run as a presbumit by default. Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
This commit is contained in:
parent
e094139b05
commit
f6a35f8786
10
Makefile
10
Makefile
@ -55,7 +55,7 @@ fuzz:
|
|||||||
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
|
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
|
||||||
verify-govet verify-license-header verify-receiver-name verify-mod-tidy \
|
verify-govet verify-license-header verify-receiver-name verify-mod-tidy \
|
||||||
verify-shellws verify-proto-annotations verify-genproto verify-yamllint \
|
verify-shellws verify-proto-annotations verify-genproto verify-yamllint \
|
||||||
verify-govet-shadow verify-markdown-marker
|
verify-govet-shadow verify-markdown-marker verify-go-versions
|
||||||
|
|
||||||
.PHONY: fix
|
.PHONY: fix
|
||||||
fix: fix-bom fix-lint fix-yamllint
|
fix: fix-bom fix-lint fix-yamllint
|
||||||
@ -187,3 +187,11 @@ clean:
|
|||||||
rm -rf ./tests/e2e/default.proxy
|
rm -rf ./tests/e2e/default.proxy
|
||||||
rm -rf ./bin/shellcheck*
|
rm -rf ./bin/shellcheck*
|
||||||
find ./ -name "127.0.0.1:*" -o -name "localhost:*" -o -name "*.log" -o -name "agent-*" -o -name "*.coverprofile" -o -name "testname-proxy-*" -delete
|
find ./ -name "127.0.0.1:*" -o -name "localhost:*" -o -name "*.log" -o -name "agent-*" -o -name "*.coverprofile" -o -name "testname-proxy-*" -delete
|
||||||
|
|
||||||
|
.PHONY: verify-go-versions
|
||||||
|
verify-go-versions:
|
||||||
|
./scripts/verify_go_versions.sh
|
||||||
|
|
||||||
|
.PHONY: sync-toolchain-directive
|
||||||
|
sync-toolchain-directive:
|
||||||
|
./scripts/sync_go_toolchain_directive.sh
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/api/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1
|
github.com/coreos/go-semver v0.3.1
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/client/v2
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.etcd.io/etcd/api/v3 v3.6.0-alpha.0
|
go.etcd.io/etcd/api/v3 v3.6.0-alpha.0
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0
|
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/client/pkg/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0
|
github.com/coreos/go-systemd/v22 v22.5.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/client/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1
|
github.com/coreos/go-semver v0.3.1
|
||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/etcdctl/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bgentry/speakeasy v0.1.0
|
github.com/bgentry/speakeasy v0.1.0
|
||||||
github.com/cheggaaa/pb/v3 v3.1.5
|
github.com/cheggaaa/pb/v3 v3.1.5
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/etcdutl/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
go.etcd.io/etcd/api/v3 => ../api
|
go.etcd.io/etcd/api/v3 => ../api
|
||||||
go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
|
go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/pkg/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/creack/pty v1.1.18
|
github.com/creack/pty v1.1.18
|
||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
|
@ -36,5 +36,7 @@ run_for_modules run ${GO_CMD} fmt || exit 2
|
|||||||
run_for_module tests bom_fix || exit 2
|
run_for_module tests bom_fix || exit 2
|
||||||
bash_ws_fix || exit 2
|
bash_ws_fix || exit 2
|
||||||
|
|
||||||
|
log_callout "Syncing go toolchain directives"
|
||||||
|
run ./scripts/sync_go_toolchain_directive.sh || exit 2
|
||||||
|
|
||||||
log_success -e "\\nSUCCESS: etcd code is fixed :)"
|
log_success -e "\\nSUCCESS: etcd code is fixed :)"
|
||||||
|
14
scripts/sync_go_toolchain_directive.sh
Executable file
14
scripts/sync_go_toolchain_directive.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script looks at the version present in the .go-version file and treats
|
||||||
|
# that to be the value of the toolchain directive that go should use. It then
|
||||||
|
# updates the toolchain directives of all go.mod files to reflect this version.
|
||||||
|
#
|
||||||
|
# We do this to ensure that .go-version acts as the source of truth for go versions.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source ./scripts/test_lib.sh
|
||||||
|
|
||||||
|
TARGET_GO_VERSION="${TARGET_GO_VERSION:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
|
||||||
|
find . -name 'go.mod' -exec go mod edit -toolchain=go"${TARGET_GO_VERSION}" {} \;
|
53
scripts/verify_go_versions.sh
Executable file
53
scripts/verify_go_versions.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script verifies that the value of the toolchain directive in the
|
||||||
|
# go.mod files always match that of the .go-version file to ensure that
|
||||||
|
# we accidentally don't test and release with differing versions of Go.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source ./scripts/test_lib.sh
|
||||||
|
|
||||||
|
target_go_version="${target_go_version:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
|
||||||
|
log_info "expected go toolchain directive: go${target_go_version}"
|
||||||
|
log_info
|
||||||
|
|
||||||
|
toolchain_out_of_sync="false"
|
||||||
|
go_line_violation="false"
|
||||||
|
|
||||||
|
# verify_go_versions takes a go.mod filepath as an argument
|
||||||
|
# and checks if:
|
||||||
|
# (1) go directive <= version in .go-version
|
||||||
|
# (2) toolchain directive == version in .go-version
|
||||||
|
function verify_go_versions() {
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
toolchain_version="$(go mod edit -json $1 | jq -r .Toolchain)"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
go_line_version="$(go mod edit -json $1 | jq -r .Go)"
|
||||||
|
if [[ "go${target_go_version}" != "${toolchain_version}" ]]; then
|
||||||
|
log_error "go toolchain directive out of sync for $1, got: ${toolchain_version}"
|
||||||
|
toolchain_out_of_sync="true"
|
||||||
|
fi
|
||||||
|
if ! printf '%s\n' "${go_line_version}" "${target_go_version}" | sort --check=silent --version-sort; then
|
||||||
|
log_error "go directive in $1 is greater than maximum allowed: go${target_go_version}"
|
||||||
|
go_line_violation="true"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
while read -r mod; do
|
||||||
|
verify_go_versions "${mod}";
|
||||||
|
done < <(find . -name 'go.mod')
|
||||||
|
|
||||||
|
if [[ "${toolchain_out_of_sync}" == "true" ]]; then
|
||||||
|
log_error
|
||||||
|
log_error "Please run scripts/sync_go_toolchain_directive.sh or update .go-version to rectify this error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${go_line_violation}" == "true" ]]; then
|
||||||
|
log_error
|
||||||
|
log_error "Please update .go-version to rectify this error, any go directive should be <= .go-version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${go_line_violation}" == "true" ]] || [[ "${toolchain_out_of_sync}" == "true" ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/server/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1
|
github.com/coreos/go-semver v0.3.1
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0
|
github.com/coreos/go-systemd/v22 v22.5.0
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/tests/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
go.etcd.io/etcd/api/v3 => ../api
|
go.etcd.io/etcd/api/v3 => ../api
|
||||||
go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
|
go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/tools/rw-heatmaps/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/spf13/cobra v1.8.0
|
github.com/spf13/cobra v1.8.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
@ -2,6 +2,8 @@ module go.etcd.io/etcd/tools/testgrid-analysis/v3
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
toolchain go1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/GoogleCloudPlatform/testgrid v0.0.173
|
github.com/GoogleCloudPlatform/testgrid v0.0.173
|
||||||
github.com/google/go-github/v60 v60.0.0
|
github.com/google/go-github/v60 v60.0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user