Skip to content

Commit da63c41

Browse files
authored
Merge pull request #485 from danilo-gemoli/fix/restore-hack-tools
Restore hack/tools module
2 parents 3e50f22 + 03ea00f commit da63c41

File tree

12 files changed

+607
-263
lines changed

12 files changed

+607
-263
lines changed

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ require (
121121
github.com/gogo/protobuf v1.3.2 // indirect
122122
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
123123
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
124-
github.com/golang/protobuf v1.5.4 // indirect
124+
github.com/golang/protobuf v1.5.4
125125
github.com/google/btree v1.0.1 // indirect
126126
github.com/google/cel-go v0.20.1 // indirect
127127
github.com/google/gnostic-models v0.6.8 // indirect
@@ -191,6 +191,13 @@ require (
191191
github.com/aws/aws-sdk-go-v2/config v1.27.27
192192
github.com/aws/aws-sdk-go-v2/credentials v1.17.27
193193
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.3
194+
github.com/client9/misspell v0.3.4
195+
github.com/go-bindata/go-bindata/v3 v3.1.3
196+
github.com/golangci/golangci-lint v1.64.8
197+
github.com/google/ko v0.14.1
198+
gotest.tools/gotestsum v1.12.3
199+
k8s.io/code-generator v0.30.1
200+
sigs.k8s.io/controller-tools v0.15.0
194201
)
195202

196203
require (
@@ -262,7 +269,6 @@ require (
262269
github.com/chavacava/garif v0.1.0 // indirect
263270
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
264271
github.com/ckaznocha/intrange v0.3.0 // indirect
265-
github.com/client9/misspell v0.3.4 // indirect
266272
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
267273
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
268274
github.com/curioswitch/go-reassign v0.3.0 // indirect
@@ -286,7 +292,6 @@ require (
286292
github.com/firefart/nonamedreturns v1.0.5 // indirect
287293
github.com/fzipp/gocyclo v0.6.0 // indirect
288294
github.com/ghostiam/protogetter v0.3.9 // indirect
289-
github.com/go-bindata/go-bindata/v3 v3.1.3 // indirect
290295
github.com/go-critic/go-critic v0.12.0 // indirect
291296
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
292297
github.com/go-openapi/analysis v0.21.4 // indirect
@@ -312,13 +317,11 @@ require (
312317
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect
313318
github.com/golangci/go-printf-func-name v0.1.0 // indirect
314319
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
315-
github.com/golangci/golangci-lint v1.64.8 // indirect
316320
github.com/golangci/misspell v0.6.0 // indirect
317321
github.com/golangci/plugin-module-register v0.1.1 // indirect
318322
github.com/golangci/revgrep v0.8.0 // indirect
319323
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
320324
github.com/google/go-containerregistry v0.19.2 // indirect
321-
github.com/google/ko v0.14.1 // indirect
322325
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
323326
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
324327
github.com/gordonklaus/ineffassign v0.1.0 // indirect
@@ -437,13 +440,10 @@ require (
437440
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
438441
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 // indirect
439442
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
440-
gotest.tools/gotestsum v1.12.3 // indirect
441443
honnef.co/go/tools v0.6.1 // indirect
442-
k8s.io/code-generator v0.30.1 // indirect
443444
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect
444445
mvdan.cc/gofumpt v0.7.0 // indirect
445446
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
446-
sigs.k8s.io/controller-tools v0.15.0 // indirect
447447
sigs.k8s.io/kind v0.20.0 // indirect
448448
)
449449

hack/make-rules/go-run/arbitrary.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
2626
cd "${REPO_ROOT}"
2727
source hack/build/setup-go.sh
2828

29+
# build gotestsum
30+
cd 'hack/tools'
31+
go build -o "${REPO_ROOT}/_bin/gotestsum" gotest.tools/gotestsum
32+
# Make sure the following is ran from root dir
33+
cd "${REPO_ROOT}"
34+
2935
(
3036
set -x;
3137
go "$@"

hack/make-rules/go-test/unit.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
4747
cd "${REPO_ROOT}"
4848
source hack/build/setup-go.sh
4949

50+
# build gotestsum
51+
cd 'hack/tools'
52+
go build -o "${REPO_ROOT}/_bin/gotestsum" gotest.tools/gotestsum
53+
cd "${REPO_ROOT}"
54+
5055
JUNIT_RESULT_DIR="${REPO_ROOT}/_output"
5156
# if we are in CI, copy to the artifact upload location
5257
if [[ -n "${ARTIFACTS:-}" ]]; then
@@ -58,7 +63,7 @@ fi
5863
set -x;
5964
umask 0022
6065
mkdir -p "${JUNIT_RESULT_DIR}"
61-
go tool gotestsum --junitfile="${JUNIT_RESULT_DIR}/junit-unit.xml" \
66+
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${JUNIT_RESULT_DIR}/junit-unit.xml" \
6267
-- \
6368
${PROW_UNIT_TEST_EXTRA_FLAGS[@]+${PROW_UNIT_TEST_EXTRA_FLAGS[@]}} \
6469
"./${folder_to_test}"

hack/make-rules/update/codegen.sh

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,26 @@ cd $REPO_ROOT
3333
echo "Ensuring go version."
3434
source ./hack/build/setup-go.sh
3535

36-
wrap-go-tool() {
37-
local tool="$1"
38-
local wrapper_name="${tool}-XXXX"
39-
wrapper="$(mktemp --tmpdir $wrapper_name)"
40-
printf '#!/usr/bin/bash\n\ngo tool %s $@\n' "$tool" >>"$wrapper"
41-
chmod +x "$wrapper"
42-
echo "$wrapper"
43-
}
44-
PROTOC_GEN_GO_WRAPPER="$(wrap-go-tool protoc-gen-go)"
45-
PROTOC_GEN_GO_GRPC_WRAPPER="$(wrap-go-tool protoc-gen-go-grpc)"
46-
36+
# build codegen tools
37+
echo "Install codegen tools."
38+
cd "hack/tools"
39+
clientgen=${REPO_ROOT}/_bin/client-gen
40+
go build -o "${clientgen}" k8s.io/code-generator/cmd/client-gen
41+
deepcopygen=${REPO_ROOT}/_bin/deepcopy-gen
42+
go build -o "${deepcopygen}" k8s.io/code-generator/cmd/deepcopy-gen
43+
informergen=${REPO_ROOT}/_bin/informer-gen
44+
go build -o "${informergen}" k8s.io/code-generator/cmd/informer-gen
45+
listergen=${REPO_ROOT}/_bin/lister-gen
46+
go build -o "${listergen}" k8s.io/code-generator/cmd/lister-gen
47+
go_bindata=${REPO_ROOT}/_bin/go-bindata
48+
go build -o "${go_bindata}" github.com/go-bindata/go-bindata/v3/go-bindata
49+
controllergen=${REPO_ROOT}/_bin/controller-gen
50+
go build -o "${controllergen}" sigs.k8s.io/controller-tools/cmd/controller-gen
51+
protoc_gen_go="${REPO_ROOT}/_bin/protoc-gen-go" # golang protobuf plugin
52+
GOBIN="${REPO_ROOT}/_bin" go install google.golang.org/protobuf/cmd/[email protected]
53+
GOBIN="${REPO_ROOT}/_bin" go install google.golang.org/grpc/cmd/[email protected]
54+
55+
cd "${REPO_ROOT}"
4756
ensure-protoc-deps() {
4857
# Install protoc
4958
if [[ ! -f "_bin/protoc/bin/protoc" ]]; then
@@ -88,15 +97,15 @@ gen-prow-config-documented() {
8897

8998
gen-deepcopy() {
9099
echo "Generating DeepCopy() methods..." >&2
91-
go tool deepcopy-gen ./... \
100+
"$deepcopygen" ./... \
92101
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
93102
--output-file zz_generated.deepcopy.go \
94103
--bounding-dirs sigs.k8s.io/prow/pkg/apis,sigs.k8s.io/prow/pkg/config
95104
}
96105

97106
gen-client() {
98107
echo "Generating client..." >&2
99-
go tool client-gen \
108+
"$clientgen" \
100109
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
101110
--clientset-name versioned \
102111
--input-base "" \
@@ -105,7 +114,7 @@ gen-client() {
105114
--output-pkg sigs.k8s.io/prow/pkg/client/clientset
106115

107116
echo "Generating client for pipeline..." >&2
108-
go tool client-gen \
117+
"$clientgen" \
109118
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
110119
--clientset-name versioned \
111120
--input-base "" \
@@ -116,29 +125,29 @@ gen-client() {
116125

117126
gen-lister() {
118127
echo "Generating lister..." >&2
119-
go tool lister-gen sigs.k8s.io/prow/pkg/apis/prowjobs/v1 \
128+
"$listergen" sigs.k8s.io/prow/pkg/apis/prowjobs/v1 \
120129
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
121130
--output-dir pkg/client/listers \
122131
--output-pkg sigs.k8s.io/prow/pkg/client/listers
123132

124133
echo "Generating lister for pipeline..." >&2
125-
go tool lister-gen github.com/tektoncd/pipeline/pkg/apis/pipeline/v1 \
134+
"$listergen" github.com/tektoncd/pipeline/pkg/apis/pipeline/v1 \
126135
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
127136
--output-dir pkg/pipeline/listers \
128137
--output-pkg sigs.k8s.io/prow/pkg/pipeline/listers
129138
}
130139

131140
gen-informer() {
132141
echo "Generating informer..." >&2
133-
go tool informer-gen sigs.k8s.io/prow/pkg/apis/prowjobs/v1 \
142+
"$informergen" sigs.k8s.io/prow/pkg/apis/prowjobs/v1 \
134143
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
135144
--versioned-clientset-package sigs.k8s.io/prow/pkg/client/clientset/versioned \
136145
--listers-package sigs.k8s.io/prow/pkg/client/listers \
137146
--output-dir pkg/client/informers \
138147
--output-pkg sigs.k8s.io/prow/pkg/client/informers
139148

140149
echo "Generating informer for pipeline..." >&2
141-
go tool informer-gen github.com/tektoncd/pipeline/pkg/apis/pipeline/v1 \
150+
"$informergen" github.com/tektoncd/pipeline/pkg/apis/pipeline/v1 \
142151
--go-header-file hack/boilerplate/boilerplate.generated.go.txt \
143152
--versioned-clientset-package sigs.k8s.io/prow/pkg/pipeline/clientset/versioned \
144153
--listers-package sigs.k8s.io/prow/pkg/pipeline/listers \
@@ -149,14 +158,14 @@ gen-informer() {
149158
gen-spyglass-bindata() {
150159
cd pkg/spyglass/lenses/common/
151160
echo "Generating spyglass bindata..." >&2
152-
go tool go-bindata -pkg=common static/
161+
$go_bindata -pkg=common static/
153162
gofmt -s -w ./
154163
cd - >/dev/null
155164
}
156165

157166
gen-prowjob-crd() {
158167
echo "Generating prowjob crd..." >&2
159-
go tool controller-gen crd:crdVersions=v1 paths=./pkg/apis/prowjobs/v1 output:stdout \
168+
"$controllergen" crd:crdVersions=v1 paths=./pkg/apis/prowjobs/v1 output:stdout \
160169
| $SED '/^$/d' \
161170
| $SED '/^spec:.*/a \ preserveUnknownFields: false' \
162171
| $SED '/^ annotations.*/a \ api-approved.kubernetes.io: https://github.com/kubernetes/test-infra/pull/8669' \
@@ -184,21 +193,22 @@ gen-proto-stubs() {
184193
# structure (so that the generated files can sit next to the .proto files,
185194
# instead of under a "k8.io/test-infra/prow/..." subfolder).
186195
"${REPO_ROOT}/_bin/protoc/bin/protoc" \
187-
--plugin=protoc-gen-go="$PROTOC_GEN_GO_WRAPPER" \
188-
--plugin=protoc-gen-go-grpc="$PROTOC_GEN_GO_GRPC_WRAPPER" \
189-
--proto_path="${REPO_ROOT}/_bin/protoc/include/google/protobuf" \
190-
--proto_path="${REPO_ROOT}/_bin/protoc/include/googleapis" \
191-
--proto_path="$dir" \
192-
--go_out="$dir" \
193-
--go_opt=paths=source_relative \
194-
--go-grpc_out="$dir" \
195-
--go-grpc_opt=paths=source_relative \
196+
"--plugin=${protoc_gen_go}" \
197+
"--proto_path=${REPO_ROOT}/_bin/protoc/include/google/protobuf" \
198+
"--proto_path=${REPO_ROOT}/_bin/protoc/include/googleapis" \
199+
"--proto_path=${dir}" \
200+
--go_out="${dir}" --go_opt=paths=source_relative \
201+
--go-grpc_out="${dir}" --go-grpc_opt=paths=source_relative \
196202
"$1"
197203
}
198204

199205
gen-all-proto-stubs() {
200206
echo >&2 "Generating proto stubs"
201207

208+
# Expose the golang protobuf plugin binaries (protoc-gen-go,
209+
# protoc-gen-go-grpc) to the PATH so that protoc can find it.
210+
export PATH="${REPO_ROOT}/_bin:$PATH"
211+
202212
while IFS= read -r -d '' proto; do
203213
echo >&2 " $proto"
204214
gen-proto-stubs "$proto"

hack/make-rules/update/misspell.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ cd $REPO_ROOT
2323
echo "Ensuring go version."
2424
source ./hack/build/setup-go.sh
2525

26+
# build misspell
27+
echo "Install misspell."
28+
cd "hack/tools"
29+
go build -o "${REPO_ROOT}/_bin/misspell" github.com/client9/misspell/cmd/misspell
30+
MISSPELL="${REPO_ROOT}/_bin/misspell"
31+
cd "${REPO_ROOT}"
32+
2633
find -L . -type f -not \( \
2734
\( \
2835
-path '*/vendor/*' \
@@ -36,8 +43,8 @@ find -L . -type f -not \( \
3643
-o -path './_output/*' \
3744
-o -path './_artifacts/*' \
3845
-o -path './bazel-*/*' \
39-
-o -path './go.mod' \
40-
-o -path './go.sum' \
46+
-o -path './hack/tools/go.mod' \
47+
-o -path './hack/tools/go.sum' \
4148
-o -path './.python_virtual_env/*' \
4249
\) -prune \
43-
\) | xargs go tool misspell -w
50+
\) | xargs "${MISSPELL}" -w

hack/make-rules/verify/golangci-lint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ if [[ ! -f .golangci.yml ]]; then
3030
exit 1
3131
fi
3232

33+
# build golangci-lint
34+
echo "Install golangci-lint."
35+
cd "hack/tools"
36+
go build -o "${REPO_ROOT}/_bin/golangci-lint" github.com/golangci/golangci-lint/cmd/golangci-lint
37+
cd "${REPO_ROOT}"
38+
3339
echo "Run golangci-lint."
3440
echo "Go version: $(go version)"
35-
echo "Golangci-lint version: $(go tool golangci-lint version)"
41+
echo "Golangci-lint version: $(./_bin/golangci-lint version)"
3642
export GO111MODULE=on
3743
export GOPROXY=https://proxy.golang.org
3844
export GOSUMDB=sum.golang.org
39-
go tool golangci-lint run ./...
45+
./_bin/golangci-lint run ./...

hack/make-rules/verify/misspell.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ set -o pipefail
2020
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
2121
cd $REPO_ROOT
2222

23+
BIN_DIR="${REPO_ROOT}/_bin/misspell"
24+
mkdir -p "$BIN_DIR"
25+
MISSPELL="${BIN_DIR}/misspell"
26+
2327
echo "Ensuring go version."
2428
source ./hack/build/setup-go.sh
2529

30+
# build misspell
31+
echo "Install misspell."
32+
cd "hack/tools"
33+
go build -o "$MISSPELL" github.com/client9/misspell/cmd/misspell
34+
cd "${REPO_ROOT}"
35+
2636
trap 'echo ERROR: found unexpected instance of "Git"hub, use github or GitHub' ERR
2737

2838
echo "Check for word 'github'..."
@@ -68,10 +78,12 @@ find -L . -type f -not \( \
6878
-o -path './_output/*' \
6979
-o -path './_artifacts/*' \
7080
-o -path './bazel-*/*' \
81+
-o -path './hack/tools/go.mod' \
82+
-o -path './hack/tools/go.sum' \
7183
-o -path './go.mod' \
7284
-o -path './go.sum' \
7385
-o -path './.python_virtual_env/*' \
7486
\) -prune \
75-
\) | xargs go tool misspell --error
87+
\) | xargs "$MISSPELL" --error
7688

7789
echo 'PASS: No spelling issues detected'

hack/prowimagebuilder/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func init() {
7171
os.Exit(1)
7272
}
7373
rootDir = out
74+
75+
if _, err := runCmdInDirFunc(path.Join(rootDir, "hack/tools"), nil, "go", "build", "-o", path.Join(rootDir, "_bin/ko"), "github.com/google/ko"); err != nil {
76+
logrus.WithError(err).Error("Failed ensure ko")
77+
os.Exit(1)
78+
}
7479
}
7580

7681
type options struct {
@@ -126,10 +131,6 @@ func runCmd(additionalEnv []string, cmd string, args ...string) (string, error)
126131
return runCmdInDirFunc(rootDir, additionalEnv, cmd, args...)
127132
}
128133

129-
func runGoToolCmd(additionalEnv []string, tool string, args ...string) (string, error) {
130-
return runCmd(additionalEnv, "go", append([]string{"tool", tool}, args...)...)
131-
}
132-
133134
type imageDef struct {
134135
Dir string `json:"dir"`
135136
Arch string `json:"arch"`
@@ -267,7 +268,7 @@ func buildAndPush(id *imageDef, dockerRepos []string, push bool) error {
267268
// to subsequent identical docker repo(s) is relatively cheap.
268269
for _, dockerRepo := range dockerRepos {
269270
logger.WithField("args", publishArgs).Info("Running ko.")
270-
if _, err = runGoToolCmd([]string{"KO_DOCKER_REPO=" + dockerRepo}, "ko", publishArgs...); err != nil {
271+
if _, err = runCmd([]string{"KO_DOCKER_REPO=" + dockerRepo}, "_bin/ko", publishArgs...); err != nil {
271272
return fmt.Errorf("running ko: %w", err)
272273
}
273274
}

0 commit comments

Comments
 (0)