From 900fc8dd7ea578fbf1944836a04e40e98a11f402 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Sun, 6 Feb 2022 14:23:28 +0800 Subject: [PATCH] replace gobin with go install The repository github.com/myitcv/gobin has already been archived, and the `go install` command accepts arguments with version suffixs starting from 1.16 (for example, go install example.com/cmd@v1.0.0). So there is no reason to continue to use gobin. --- scripts/test_lib.sh | 22 +++++++++++++--------- tests/Dockerfile | 1 - tools/mod/install_all.sh | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/scripts/test_lib.sh b/scripts/test_lib.sh index 7c2d0403f..062aeb220 100644 --- a/scripts/test_lib.sh +++ b/scripts/test_lib.sh @@ -353,23 +353,27 @@ function tool_exists { fi } -# Ensure gobin is available, as it runs majority of the tools -if ! command -v "gobin" >/dev/null; then - GOARCH="" run env GO111MODULE=off go get github.com/myitcv/gobin || exit 1 -fi - # tool_get_bin [tool] - returns absolute path to a tool binary (or returns error) function tool_get_bin { - tool_exists "gobin" "GO111MODULE=off go get github.com/myitcv/gobin" || return 2 - local tool="$1" + local pkg_part="$1" if [[ "$tool" == *"@"* ]]; then + pkg_part=$(echo "${tool}" | cut -d'@' -f1) # shellcheck disable=SC2086 - run gobin ${GOBINARGS:-} -p "${tool}" || return 2 + run go install ${GOBINARGS:-} "${tool}" || return 2 else # shellcheck disable=SC2086 - run_for_module ./tools/mod run gobin ${GOBINARGS:-} -p -m --mod=readonly "${tool}" || return 2 + run_for_module ./tools/mod run go install ${GOBINARGS:-} "${tool}" || return 2 fi + + # remove the version suffix, such as removing "/v3" from "go.etcd.io/etcd/v3". + local cmd_base_name + cmd_base_name=$(basename "${pkg_part}") + if [[ ${cmd_base_name} =~ ^v[0-9]*$ ]]; then + pkg_part=$(dirname "${pkg_part}") + fi + + command -v "$(basename "${pkg_part}")" } # tool_pkg_dir [pkg] - returns absolute path to a directory that stores given pkg. diff --git a/tests/Dockerfile b/tests/Dockerfile index f6e5e7447..091398fe3 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -44,7 +44,6 @@ WORKDIR ${GOPATH}/src/go.etcd.io/etcd ADD ./scripts/install-marker.sh /tmp/install-marker.sh -RUN GO111MODULE=off go get github.com/myitcv/gobin RUN /tmp/install-marker.sh amd64 \ && rm -f /tmp/install-marker.sh \ && curl -s https://codecov.io/bash >/codecov \ diff --git a/tools/mod/install_all.sh b/tools/mod/install_all.sh index 7de5fb014..2f099b5ea 100755 --- a/tools/mod/install_all.sh +++ b/tools/mod/install_all.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash cd ./tools/mod || exit 2 -go list --tags tools -f '{{ join .Imports "\n" }}' | xargs gobin -p +go list --tags tools -f '{{ join .Imports "\n" }}' | xargs go install