Skip to content

Commit 1ad69b8

Browse files
chore: Improve performance of make verify (#1382)
1 parent 089058f commit 1ad69b8

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ benchmark:
8282
coverage:
8383
go tool cover -html coverage.out -o coverage.html
8484

85-
verify: toolchain tidy download ## Verify code. Includes dependencies, linting, formatting, etc
85+
verify: tidy download ## Verify code. Includes dependencies, linting, formatting, etc
86+
SKIP_INSTALLED=true make toolchain
8687
make az-swagger-generate-clients-raw
8788
go generate ./...
8889
hack/boilerplate.sh

hack/toolchain.sh

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,76 @@ set -euo pipefail
44
K8S_VERSION="${K8S_VERSION:="1.29.x"}"
55
KUBEBUILDER_ASSETS="/usr/local/kubebuilder/bin"
66

7+
# Default SKIP_INSTALLED to false if not set
8+
SKIP_INSTALLED="${SKIP_INSTALLED:=false}"
9+
10+
if [ "$SKIP_INSTALLED" == true ]; then
11+
echo "[INF] Skipping tools already installed."
12+
fi
13+
14+
# This is where go install will put things
15+
TOOL_DEST="$(go env GOPATH)/bin"
16+
717
main() {
818
tools
919
kubebuilder
1020
gettrivy
1121
}
1222

23+
# should-skip is a helper function to determine if installation of a tool should be skipped
24+
# $1 is the expected command
25+
should-skip() {
26+
if [ "$SKIP_INSTALLED" == true ] && [ -f "$TOOL_DEST/$1" ]; then
27+
# We can skip installation
28+
return 0
29+
fi
30+
31+
# Installation is needed
32+
return 1
33+
}
34+
35+
# go-install is a helper function to install go tools
36+
# $1 is the expected command
37+
# $2 is the go install path
38+
go-install() {
39+
# Check to see if we need to install
40+
if should-skip "$1"; then
41+
# Silently skip, to avoid console debris
42+
# echo "[INF] $1 is already installed, skipping."
43+
return
44+
fi
45+
46+
echo "[INF] Installing $1"
47+
go install "$2"
48+
}
49+
1350
tools() {
14-
go install github.com/google/go-licenses@v1.6.0
15-
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
16-
go install github.com/google/ko@v0.17.1
17-
go install github.com/mikefarah/yq/v4@v4.45.1
18-
go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
19-
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
20-
go install github.com/sigstore/cosign/v2/cmd/cosign@v2.4.1
51+
go-install go-licenses github.com/google/go-licenses@v1.6.0
52+
go-install ko github.com/google/ko@v0.17.1
53+
go-install yq github.com/mikefarah/yq/v4@v4.45.1
54+
go-install helm-docs github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
55+
go-install controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
56+
go-install cosign github.com/sigstore/cosign/v2/cmd/cosign@v2.4.1
2157
# go install -tags extended github.com/gohugoio/hugo@v0.110.0
22-
go install golang.org/x/vuln/cmd/govulncheck@v1.1.4
23-
go install github.com/onsi/ginkgo/v2/ginkgo@latest
24-
go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.7
25-
go install github.com/mattn/goveralls@v0.0.12
26-
go install github.com/google/go-containerregistry/cmd/crane@v0.20.2
27-
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1
28-
go install github.com/Azure/aks-node-viewer/cmd/aks-node-viewer@latest
29-
go install github.com/google/pprof@latest
58+
go-install govulncheck golang.org/x/vuln/cmd/govulncheck@v1.1.4
59+
go-install ginkgo github.com/onsi/ginkgo/v2/ginkgo@latest
60+
go-install actionlint github.com/rhysd/actionlint/cmd/actionlint@v1.7.7
61+
go-install goveralls github.com/mattn/goveralls@v0.0.12
62+
go-install crane github.com/google/go-containerregistry/cmd/crane@v0.20.2
63+
go-install swagger github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1
64+
go-install aks-node-viewer github.com/Azure/aks-node-viewer/cmd/aks-node-viewer@latest
65+
go-install pprof github.com/google/pprof@latest
3066

3167
if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then
3268
echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'."
3369
fi
70+
71+
go-install golangci-lint github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
72+
3473
}
3574

3675
kubebuilder() {
76+
echo "[INF] Setting up kubebuilder binaries for Kubernetes ${K8S_VERSION}"
3777
sudo mkdir -p "${KUBEBUILDER_ASSETS}"
3878
sudo chown "${USER}" "${KUBEBUILDER_ASSETS}"
3979
arch=$(go env GOARCH)

0 commit comments

Comments
 (0)