Skip to content

Commit

Permalink
make update-all & ensure bazel-only targets are runnable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
SgtCoDFish committed Jun 30, 2022
1 parent 2efc0d3 commit 642161a
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
_bin
38 changes: 37 additions & 1 deletion hack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ CONTROLLER_GEN = "@io_k8s_sigs_controller_tools//cmd/controller-gen"

# Bazel file generation rules

sh_binary(
name = "update-deps",
srcs = ["update-deps.sh"],
args = [
"$(location %s)" % GO,
"$(location %s)" % GAZELLE,
"$(location %s)" % KAZEL,
"$(location :update-bazel)",
"$(location :update-deps-licenses)",
],
data = [
GAZELLE,
GO,
KAZEL,
":update-bazel",
":update-deps-licenses",
],
tags = ["manual"],
)

sh_binary(
name = "update-bazel",
srcs = ["update-bazel.sh"],
Expand All @@ -27,6 +47,19 @@ sh_binary(
GAZELLE,
KAZEL,
],
tags = ["manual"],
)

sh_binary(
name = "update-deps-licenses",
srcs = ["update-deps-licenses.sh"],
args = [
"$(location %s)" % GO,
],
data = [
GO,
],
tags = ["manual"],
)

sh_test(
Expand All @@ -41,7 +74,10 @@ sh_test(
GAZELLE,
KAZEL,
],
tags = ["lint"],
tags = [
"lint",
"manual",
],
)

filegroup(
Expand Down
20 changes: 10 additions & 10 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020 The cert-manager Authors.

# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,17 +18,16 @@ set -o errexit
set -o nounset
set -o pipefail

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


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

echo -e "\033[0;33mThis script is preserved for legacy reasons, and as such will also update bazel
You shouldn't need to run this script or install bazel for normal development.
Use 'make update-all' to do everything this script does without touching bazel\033[0m"

"$hack"/update-bazel.sh
# update-codegen is done by make now, no need to call it here
# "$hack"/update-codegen.sh
# update-crds is done by make now, no need to call it here
# "$hack"/update-crds.sh
"$hack"/update-deps.sh
# This is already run automatically by update-deps.sh
#"$hack"/update-deps-licenses.sh
"$hack"/update-gofmt.sh

make update-all
14 changes: 7 additions & 7 deletions hack/update-bazel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020 The cert-manager Authors.

# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,14 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

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
echo "Install bazel at https://bazel.build" >&2
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
echo "If you need to run this script, install bazel from https://bazel.build" >&2
exit 1
else
(
Expand All @@ -35,11 +40,6 @@ 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 \
--exclude=_bin \
Expand Down
39 changes: 5 additions & 34 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

# Copyright 2020 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

# Update vendor and bazel rules to match go.mod
#
Expand All @@ -26,7 +29,8 @@ set -o pipefail
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
echo "Updating modules..." >&2
elif ! command -v bazel &>/dev/null; then
echo "Install bazel at https://bazel.build" >&2
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
echo "If you need to run this script, install bazel from https://bazel.build" >&2
exit 1
else
(
Expand Down Expand Up @@ -55,39 +59,6 @@ shift 5
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
unset GOROOT

# Update hack/build/repos.bzl based of the go.mod file
"$gazelle" update-repos \
--from_file=go.mod --to_macro=hack/build/repos.bzl%go_repositories \
Expand Down
10 changes: 8 additions & 2 deletions hack/verify-bazel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020 The cert-manager Authors.

# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,14 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

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
echo "Install bazel at https://bazel.build" >&2
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
echo "If you need to run this script, install bazel from https://bazel.build" >&2
exit 1
else
(
Expand All @@ -44,6 +49,7 @@ export GO111MODULE=on
# get a confusing error message, but we fail fast and it is clear that
# something is wrong:
# 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

echo "Running gazelle..."
gazelle_diff=$("$gazelle" fix --go_naming_convention=go_default_library --mode=diff --external=external || true)
echo "Running kazel..."
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-chart-version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2020 The cert-manager Authors.
# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ set -o pipefail
# This file is kept as backwards-compatibility for people with muscle memory who
# type "./hack/verify-codegen.sh" and expect it to work, or for third party CI pipelines.

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

make verify-codegen
2 changes: 1 addition & 1 deletion hack/verify-crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ set -o pipefail
# This file is kept as backwards-compatibility for people with muscle memory who
# type "./hack/verify-crds.sh" and expect it to work, or for third party CI pipelines.

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

make verify-crds
9 changes: 7 additions & 2 deletions hack/verify-deps.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020 The cert-manager Authors.

# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,14 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

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

if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
echo "Checking modules for changes..." >&2
elif ! command -v bazel &>/dev/null; then
echo "Install bazel at https://bazel.build" >&2
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
echo "If you need to run this script, install bazel from https://bazel.build" >&2
exit 1
else
(
Expand Down
6 changes: 4 additions & 2 deletions hack/verify-errexit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# +skip_license_check

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

# Should usually be called via make: `make verify-errexit`

set -o errexit
set -o nounset
set -o pipefail
Expand All @@ -31,7 +33,7 @@ echo "+++ validating all scripts set '-o errexit'" >&2
if [ "$*" != "" ]; then
args="$*"
else
args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' | grep -v 'bin' )
args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' | grep -v 'bin' | grep -v '_bin' )
fi

# Gather the list of files that appear to be shell scripts.
Expand Down
28 changes: 5 additions & 23 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
echo "Validating go source file formatting..." >&2
elif ! 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-gofmt
)
exit 0
fi
# This file is kept as backwards-compatibility for people with muscle memory who
# type "./hack/verify-gofmt.sh" and expect it to work, or for third party CI pipelines.

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

export GO111MODULE=on

echo "+++ Running gofmt"
output=$(find . -name '*.go' | grep -v 'vendor/' | xargs "$gofmt" -s -d)
if [ ! -z "${output}" ]; then
echo "${output}"
echo "Please run 'bazel run //hack:update-gofmt'"
exit 1
fi
make verify-imports
13 changes: 9 additions & 4 deletions hack/verify-staticcheck.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

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

# See https://github.com/cert-manager/cert-manager/pull/3037#issue-440523030

# Currently only works on linux/amd64, darwin/amd64.

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

Expand Down
2 changes: 1 addition & 1 deletion hack/verify-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

0 comments on commit 642161a

Please sign in to comment.