Skip to content

Commit

Permalink
Use repo-infra version of {update,verify}-{bazel,deps}
Browse files Browse the repository at this point in the history
  • Loading branch information
fejta committed Sep 27, 2019
1 parent 2259b82 commit 25a06ac
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 238 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ k8s_repositories()

git_repository(
name = "io_k8s_repo_infra",
commit = "1fedfadec8ce38e3738e516fb47227f0abd79245",
commit = "ba920646cd8793c08fb89e746e103633bec86114",
remote = "https://github.com/kubernetes/repo-infra.git",
shallow_since = "1569036205 -0700",
shallow_since = "1569559776 -0700",
)

# https://github.com/bazelbuild/rules_nodejs
Expand Down
76 changes: 6 additions & 70 deletions hack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -216,79 +216,15 @@ sh_test(

test_suite(
name = "verify-all",
tags = ["lint"], # picks up all non-manual targets with this tag
)

GAZELLE = "@bazel_gazelle//cmd/gazelle"

KAZEL = "@io_k8s_repo_infra//cmd/kazel"

GO = "@go_sdk//:bin/go"

sh_binary(
name = "update-deps",
srcs = ["update-deps.sh"],
args = [
"$(location %s)" % GO,
"$(location %s)" % GAZELLE,
"$(location %s)" % KAZEL,
"$(location :update-bazel)",
],
data = [
GAZELLE,
GO,
KAZEL,
":update-bazel",
tests = [
":verify-linters",
"@io_k8s_repo_infra//hack:verify-all",
],
)

sh_test(
name = "verify-deps",
srcs = ["verify-deps.sh"],
args = [
"$(location :update-deps)",
"$(location %s)" % GO,
"$(location %s)" % GAZELLE,
"$(location %s)" % KAZEL,
"$(location :update-bazel)",
],
data = [
GAZELLE,
GO,
KAZEL,
":update-bazel",
":update-deps",
"@//:all-srcs",
],
tags = ["lint"],
)

sh_binary(
name = "update-bazel",
srcs = ["update-bazel.sh"],
args = [
"$(location %s)" % GAZELLE,
"$(location %s)" % KAZEL,
],
data = [
GAZELLE,
KAZEL,
],
)

sh_test(
name = "verify-bazel",
srcs = ["verify-bazel.sh"],
args = [
"$(location %s)" % GAZELLE,
"$(location %s)" % KAZEL,
],
data = [
"@//:all-srcs",
GAZELLE,
KAZEL,
],
tags = ["lint"],
test_suite(
name = "verify-linters",
tags = ["lint"], # picks up all non-manual targets with this tag
)

py_binary(
Expand Down
30 changes: 2 additions & 28 deletions hack/update-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,10 @@ set -o errexit
set -o nounset
set -o pipefail

if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
echo "Updating bazel rules..." >&2
elif ! command -v bazel &>/dev/null; then
if ! command -v bazel &>/dev/null; then
echo "Install bazel at https://bazel.build" >&2
exit 1
elif ! bazel query @com_github_bazelbuild_bazel_gazelle//cmd/gazelle &>/dev/null; then
(
set -o xtrace
bazel run @io_k8s_test_infra//hack:bootstrap-testinfra
bazel run @io_k8s_test_infra//hack:update-bazel
)
exit 0
else
(
set -o xtrace
bazel run @io_k8s_test_infra//hack:update-bazel
)
exit 0
fi

gazelle=$(realpath "$1")
kazel=$(realpath "$2")

cd "$BUILD_WORKSPACE_DIRECTORY"

if [[ ! -f go.mod ]]; then
echo "No module defined, see https://github.com/golang/go/wiki/Modules#how-to-define-a-module" >&2
exit 1
fi

set -o xtrace
"$gazelle" fix --external=external
"$kazel" --cfg-path=./hack/.kazelcfg.json
bazel run @io_k8s_repo_infra//hack:update-bazel
71 changes: 4 additions & 67 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.


# Update vendor and bazel rules to match go.mod
#
# Usage:
# update-deps.sh [--patch|--minor] [packages]

set -o nounset
set -o errexit
set -o nounset
set -o pipefail

if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
echo "Updating modules..." >&2
elif ! command -v bazel &>/dev/null; then
if ! command -v bazel &>/dev/null; then
echo "Install bazel at https://bazel.build" >&2
exit 1
else
(
set -o xtrace
bazel run @io_k8s_test_infra//hack:update-deps -- "$@"
)
exit 0
fi

go=$(realpath "$1")
export PATH=$(dirname "$go"):$PATH
gazelle=$(realpath "$2")
kazel=$(realpath "$3")
update_bazel=(
$(realpath "$4")
"$gazelle"
"$kazel"
)

shift 4

cd "$BUILD_WORKSPACE_DIRECTORY"
trap 'echo "FAILED" >&2' ERR

export GO111MODULE=on
export GOPROXY=https://proxy.golang.org
export GOSUMDB=sum.golang.org
mode="${1:-}"
shift || true
case "$mode" in
--minor)
if [[ -z "$@" ]]; then
"$go" get -u ./...
else
"$go" get -u "$@"
fi
;;
--patch)
if [[ -z "$@" ]]; then
"$go" get -u=patch ./...
else
"$go" get -u=patch "$@"
fi
;;
"")
# Just validate, or maybe manual go.mod edit
;;
*)
echo "Usage: $(basename "$0") [--patch|--minor] [packages]" >&2
exit 1
;;
esac

rm -rf vendor
"$go" mod tidy
"$gazelle" update-repos \
--from_file=go.mod --to_macro=repos.bzl%go_repositories \
--build_file_generation=on --build_file_proto_mode=disable
"${update_bazel[@]}" # TODO(fejta): do we still need to do this?
echo "SUCCESS: updated modules"
set -o xtrace
bazel run @io_k8s_repo_infra//hack:update-deps -- "$@"
29 changes: 3 additions & 26 deletions hack/verify-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,10 @@ set -o errexit
set -o nounset
set -o pipefail

if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
echo "Validating bazel rules..." >&2
elif ! command -v bazel &> /dev/null; then
if ! command -v bazel &> /dev/null; then
echo "Install bazel at https://bazel.build" >&2
exit 1
elif ! bazel query @//:all-srcs union @io_k8s_test_infra//hack:update-bazel &>/dev/null; then
echo "ERROR: bazel rules need bootstrapping. Run hack/update-bazel.sh" >&2
exit 1
else
(
set -o xtrace
bazel test --test_output=streamed @io_k8s_test_infra//hack:verify-bazel
)
exit 0
fi

gazelle=$1
kazel=$2

gazelle_diff=$("$gazelle" fix --mode=diff --external=external)
kazel_diff=$("$kazel" --dry-run --print-diff --cfg-path=./hack/.kazelcfg.json)

if [[ -n "${gazelle_diff}${kazel_diff}" ]]; then
echo "Current rules (-) do not match expected (+):" >&2
echo "${gazelle_diff}"
echo "${kazel_diff}"
echo
echo "ERROR: bazel rules out of date. Fix with ./hack/update-bazel.sh" >&2
exit 1
fi
set -o xtrace
bazel test --test_output=streamed @io_k8s_repo_infra//hack:verify-bazel
49 changes: 4 additions & 45 deletions hack/verify-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o nounset
set -o errexit
set -o nounset
set -o pipefail

if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
echo "Checking modules for changes..." >&2
elif ! command -v bazel &>/dev/null; then
if ! command -v bazel &>/dev/null; then
echo "Install bazel at https://bazel.build" >&2
exit 1
else
(
set -o xtrace
bazel test --test_output=streamed //hack:verify-deps
)
exit 0
fi


tmpfiles=$TEST_TMPDIR/files

(
mkdir -p "$tmpfiles"
rm -f bazel-*
cp -aL "." "$tmpfiles"
export BUILD_WORKSPACE_DIRECTORY=$tmpfiles
export HOME=$(realpath "$TEST_TMPDIR/home")
unset GOPATH
go=$(realpath "$2")
export PATH=$(dirname "$go"):$PATH
"$@"
)

(
# Remove the platform/binary for gazelle and kazel
gazelle=$(dirname "$3")
kazel=$(dirname "$4")
rm -rf {.,"$tmpfiles"}/{"$gazelle","$kazel"}
)
# Avoid diff -N so we handle empty files correctly
diff=$(diff -upr \
-x ".git" \
-x "bazel-*" \
-x "_output" \
"." "$tmpfiles" 2>/dev/null || true)

if [[ -n "${diff}" ]]; then
echo "${diff}" >&2
echo >&2
echo "ERROR: modules changed. Update with ./hack/update-deps.sh" >&2
exit 1
fi
echo "SUCCESS: modules up-to-date"
set -o xtrace
bazel test --test_output=streamed //hack:verify-deps

0 comments on commit 25a06ac

Please sign in to comment.