Skip to content

Commit 642161a

Browse files
committed
make update-all & ensure bazel-only targets are runnable
this allows us to maintain the bazel build files until they're removed, but tries to avoid accidentally encouraging their use `make update-all` implementes a non-bazel version of `hack/update-all.sh`, with `hack/update-all.sh` now calling make but also doing the bazel stuff it used to. Signed-off-by: Ashley Davis <[email protected]>
1 parent 2efc0d3 commit 642161a

15 files changed

+106
-92
lines changed

.bazelignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
_bin

hack/BUILD.bazel

+37-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ CONTROLLER_GEN = "@io_k8s_sigs_controller_tools//cmd/controller-gen"
1616

1717
# Bazel file generation rules
1818

19+
sh_binary(
20+
name = "update-deps",
21+
srcs = ["update-deps.sh"],
22+
args = [
23+
"$(location %s)" % GO,
24+
"$(location %s)" % GAZELLE,
25+
"$(location %s)" % KAZEL,
26+
"$(location :update-bazel)",
27+
"$(location :update-deps-licenses)",
28+
],
29+
data = [
30+
GAZELLE,
31+
GO,
32+
KAZEL,
33+
":update-bazel",
34+
":update-deps-licenses",
35+
],
36+
tags = ["manual"],
37+
)
38+
1939
sh_binary(
2040
name = "update-bazel",
2141
srcs = ["update-bazel.sh"],
@@ -27,6 +47,19 @@ sh_binary(
2747
GAZELLE,
2848
KAZEL,
2949
],
50+
tags = ["manual"],
51+
)
52+
53+
sh_binary(
54+
name = "update-deps-licenses",
55+
srcs = ["update-deps-licenses.sh"],
56+
args = [
57+
"$(location %s)" % GO,
58+
],
59+
data = [
60+
GO,
61+
],
62+
tags = ["manual"],
3063
)
3164

3265
sh_test(
@@ -41,7 +74,10 @@ sh_test(
4174
GAZELLE,
4275
KAZEL,
4376
],
44-
tags = ["lint"],
77+
tags = [
78+
"lint",
79+
"manual",
80+
],
4581
)
4682

4783
filegroup(

hack/update-all.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 The cert-manager Authors.
2+
3+
# Copyright 2022 The cert-manager Authors.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -17,17 +18,16 @@ set -o errexit
1718
set -o nounset
1819
set -o pipefail
1920

20-
# Runs all hack/update-*.sh scripts
21+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
22+
# It's preserved for now but might be removed in the future
2123

2224

2325
hack=$(dirname "${BASH_SOURCE[0]}")
2426

27+
echo -e "\033[0;33mThis script is preserved for legacy reasons, and as such will also update bazel
28+
You shouldn't need to run this script or install bazel for normal development.
29+
Use 'make update-all' to do everything this script does without touching bazel\033[0m"
30+
2531
"$hack"/update-bazel.sh
26-
# update-codegen is done by make now, no need to call it here
27-
# "$hack"/update-codegen.sh
28-
# update-crds is done by make now, no need to call it here
29-
# "$hack"/update-crds.sh
30-
"$hack"/update-deps.sh
31-
# This is already run automatically by update-deps.sh
32-
#"$hack"/update-deps-licenses.sh
33-
"$hack"/update-gofmt.sh
32+
33+
make update-all

hack/update-bazel.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 The cert-manager Authors.
2+
3+
# Copyright 2022 The cert-manager Authors.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -13,14 +14,18 @@
1314
# See the License for the specific language governing permissions and
1415
# limitations under the License.
1516

17+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
18+
# It's preserved for now but might be removed in the future
19+
1620
set -o errexit
1721
set -o nounset
1822
set -o pipefail
1923

2024
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
2125
echo "Updating bazel rules..." >&2
2226
elif ! command -v bazel &>/dev/null; then
23-
echo "Install bazel at https://bazel.build" >&2
27+
echo "This script is preserved for legacy reasons and requires bazel. You shouldn't need to run this as part of your normal development workflow" >&2
28+
echo "If you need to run this script, install bazel from https://bazel.build" >&2
2429
exit 1
2530
else
2631
(
@@ -35,11 +40,6 @@ kazel=$(realpath "$2")
3540

3641
cd "$BUILD_WORKSPACE_DIRECTORY"
3742

38-
if [[ ! -f go.mod ]]; then
39-
echo "No module defined, see https://github.com/golang/go/wiki/Modules#how-to-define-a-module" >&2
40-
exit 1
41-
fi
42-
4343
set -o xtrace
4444
"$gazelle" fix \
4545
--exclude=_bin \

hack/update-deps.sh

+5-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
23
# Copyright 2020 The cert-manager Authors.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +14,8 @@
1314
# See the License for the specific language governing permissions and
1415
# limitations under the License.
1516

17+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
18+
# It's preserved for now but might be removed in the future
1619

1720
# Update vendor and bazel rules to match go.mod
1821
#
@@ -26,7 +29,8 @@ set -o pipefail
2629
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
2730
echo "Updating modules..." >&2
2831
elif ! command -v bazel &>/dev/null; then
29-
echo "Install bazel at https://bazel.build" >&2
32+
echo "This script is preserved for legacy reasons and requires bazel. You shouldn't need to run this as part of your normal development workflow" >&2
33+
echo "If you need to run this script, install bazel from https://bazel.build" >&2
3034
exit 1
3135
else
3236
(
@@ -55,39 +59,6 @@ shift 5
5559
cd "$BUILD_WORKSPACE_DIRECTORY"
5660
trap 'echo "FAILED" >&2' ERR
5761

58-
export GO111MODULE=on
59-
export GOPROXY=https://proxy.golang.org
60-
export GOSUMDB=sum.golang.org
61-
mode="${1:-}"
62-
shift || true
63-
case "$mode" in
64-
--minor)
65-
if [[ -z "$@" ]]; then
66-
"$go" get -u ./...
67-
else
68-
"$go" get -u "$@"
69-
fi
70-
;;
71-
--patch)
72-
if [[ -z "$@" ]]; then
73-
"$go" get -u=patch ./...
74-
else
75-
"$go" get -u=patch "$@"
76-
fi
77-
;;
78-
"")
79-
# Just validate, or maybe manual go.mod edit
80-
;;
81-
*)
82-
echo "Usage: $(basename "$0") [--patch|--minor] [packages]" >&2
83-
exit 1
84-
;;
85-
esac
86-
87-
rm -rf vendor
88-
"$go" mod tidy
89-
unset GOROOT
90-
9162
# Update hack/build/repos.bzl based of the go.mod file
9263
"$gazelle" update-repos \
9364
--from_file=go.mod --to_macro=hack/build/repos.bzl%go_repositories \

hack/verify-bazel.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 The cert-manager Authors.
2+
3+
# Copyright 2022 The cert-manager Authors.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -13,14 +14,18 @@
1314
# See the License for the specific language governing permissions and
1415
# limitations under the License.
1516

17+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
18+
# It's preserved for now but might be removed in the future
19+
1620
set -o errexit
1721
set -o nounset
1822
set -o pipefail
1923

2024
if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
2125
echo "Validating bazel rules..." >&2
2226
elif ! command -v bazel &> /dev/null; then
23-
echo "Install bazel at https://bazel.build" >&2
27+
echo "This script is preserved for legacy reasons and requires bazel. You shouldn't need to run this as part of your normal development workflow" >&2
28+
echo "If you need to run this script, install bazel from https://bazel.build" >&2
2429
exit 1
2530
else
2631
(
@@ -44,6 +49,7 @@ export GO111MODULE=on
4449
# get a confusing error message, but we fail fast and it is clear that
4550
# something is wrong:
4651
# gazelle: finding module path for import github.com/cert-manager/cert-manager/test/unit/gen: exit status 1: build cache is required, but could not be located: GOCACHE is not defined and $HOME is not defined
52+
4753
echo "Running gazelle..."
4854
gazelle_diff=$("$gazelle" fix --go_naming_convention=go_default_library --mode=diff --external=external || true)
4955
echo "Running kazel..."

hack/verify-chart-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2020 The cert-manager Authors.
3+
# Copyright 2022 The cert-manager Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

hack/verify-codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ set -o pipefail
2121
# This file is kept as backwards-compatibility for people with muscle memory who
2222
# type "./hack/verify-codegen.sh" and expect it to work, or for third party CI pipelines.
2323

24-
# This script may be removed in the future. Prefer using `make verify-codegen` directly.
24+
# This script may be removed in the future. Prefer using `make` directly.
2525

2626
make verify-codegen

hack/verify-crds.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ set -o pipefail
2121
# This file is kept as backwards-compatibility for people with muscle memory who
2222
# type "./hack/verify-crds.sh" and expect it to work, or for third party CI pipelines.
2323

24-
# This script may be removed in the future. Prefer using `make verify-crds` directly.
24+
# This script may be removed in the future. Prefer using `make` directly.
2525

2626
make verify-crds

hack/verify-deps.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 The cert-manager Authors.
2+
3+
# Copyright 2022 The cert-manager Authors.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -13,14 +14,18 @@
1314
# See the License for the specific language governing permissions and
1415
# limitations under the License.
1516

17+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
18+
# It's preserved for now but might be removed in the future
19+
1620
set -o nounset
1721
set -o errexit
1822
set -o pipefail
1923

2024
if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
2125
echo "Checking modules for changes..." >&2
2226
elif ! command -v bazel &>/dev/null; then
23-
echo "Install bazel at https://bazel.build" >&2
27+
echo "This script is preserved for legacy reasons and requires bazel. You shouldn't need to run this as part of your normal development workflow" >&2
28+
echo "If you need to run this script, install bazel from https://bazel.build" >&2
2429
exit 1
2530
else
2631
(

hack/verify-errexit.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# +skip_license_check
44

@@ -22,6 +22,8 @@
2222
# Usage: verify-errexit.sh [ dir | file ... ]
2323
# default args is the root of our source tree
2424

25+
# Should usually be called via make: `make verify-errexit`
26+
2527
set -o errexit
2628
set -o nounset
2729
set -o pipefail
@@ -31,7 +33,7 @@ echo "+++ validating all scripts set '-o errexit'" >&2
3133
if [ "$*" != "" ]; then
3234
args="$*"
3335
else
34-
args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' | grep -v 'bin' )
36+
args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' | grep -v 'bin' | grep -v '_bin' )
3537
fi
3638

3739
# Gather the list of files that appear to be shell scripts.

hack/verify-gofmt.sh

+5-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2020 The cert-manager Authors.
3+
# Copyright 2022 The cert-manager Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -18,27 +18,9 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
22-
echo "Validating go source file formatting..." >&2
23-
elif ! command -v bazel &> /dev/null; then
24-
echo "Install bazel at https://bazel.build" >&2
25-
exit 1
26-
else
27-
(
28-
set -o xtrace
29-
bazel test --test_output=streamed //hack:verify-gofmt
30-
)
31-
exit 0
32-
fi
21+
# This file is kept as backwards-compatibility for people with muscle memory who
22+
# type "./hack/verify-gofmt.sh" and expect it to work, or for third party CI pipelines.
3323

34-
gofmt=$(realpath "$1")
24+
# This script may be removed in the future. Prefer using `make` directly.
3525

36-
export GO111MODULE=on
37-
38-
echo "+++ Running gofmt"
39-
output=$(find . -name '*.go' | grep -v 'vendor/' | xargs "$gofmt" -s -d)
40-
if [ ! -z "${output}" ]; then
41-
echo "${output}"
42-
echo "Please run 'bazel run //hack:update-gofmt'"
43-
exit 1
44-
fi
26+
make verify-imports

hack/verify-staticcheck.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2020 The cert-manager Authors.
3+
# Copyright 2022 The cert-manager Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -18,9 +18,14 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
# This script is currently not run as part of any automated tests.
22-
# https://github.com/cert-manager/cert-manager/pull/3037#issue-440523030
23-
# It will also currently only work on linux/amd64, darwin/amd64.
21+
# NB: This script requires bazel, and is no longer supported since we no longer support bazel
22+
# We want to add something like this to make, but since this script was never part of any CI
23+
# pipeline it's not a priority. The script is kept for backwards compatibility for now but may
24+
# change or be removed in the future.
25+
26+
# See https://github.com/cert-manager/cert-manager/pull/3037#issue-440523030
27+
28+
# Currently only works on linux/amd64, darwin/amd64.
2429

2530
REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" > /dev/null && pwd )"
2631

hack/verify-upgrade.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2021 The cert-manager Authors.
3+
# Copyright 2022 The cert-manager Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)