Skip to content

Commit aa775d8

Browse files
committed
Add v2/Makefile and call it for each rule
1 parent 68c51d8 commit aa775d8

File tree

5 files changed

+79
-14
lines changed

5 files changed

+79
-14
lines changed

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
all:
22
go build ./...
3-
go -C v2 build ./...
3+
make -C v2 all
44

55
test:
66
go test -race ./...
7-
go -C v2 test -race ./...
8-
(cd v2 && ./hack/verify-examples.sh)
7+
go -C ./examples/defaulter-gen/_output_tests test ./...
8+
make -C v2 test
99

1010
# We verify for the maximum version of the go directive as 1.20
1111
# here because the oldest go directive that exists on our supported
1212
# release branches in k/k is 1.20.
1313
verify:
1414
./hack/verify-examples.sh
1515
./hack/verify-go-directive.sh 1.20
16-
./v2/hack/verify-examples.sh
17-
cd v2 && ../hack/verify-go-directive.sh 1.20
16+
make -C v2 verify

hack/verify-examples.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ find ./examples -name "zz_generated.go" -type f -delete
3232
find ./examples/set-gen/sets -maxdepth 1 -type f -not -name "set_test.go" -not -name "doc.go" -delete
3333

3434
# Generate set-gen first since others depend on it
35-
echo "Generating example output..."
36-
go generate ./examples/set-gen/...
35+
echo "Generating example output"
3736
go generate ./examples/...
38-
pushd ./examples/defaulter-gen/_output_tests; go generate ./...; popd
37+
go -C ./examples/defaulter-gen/_output_tests generate ./...
3938

4039
# If there are any differences with committed files, fail
4140
if ! git diff --quiet HEAD; then
@@ -44,7 +43,5 @@ if ! git diff --quiet HEAD; then
4443
exit 1
4544
fi
4645

47-
echo "Running tests..."
48-
go test ./examples/...
46+
echo "Running import-boss"
4947
go run ./examples/import-boss/main.go -i $(go list k8s.io/gengo/... | grep -v import-boss/tests | paste -sd',' -) --verify-only
50-
pushd ./examples/defaulter-gen/_output_tests; go test ./...; popd

v2/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all:
2+
go build ./...
3+
4+
test:
5+
go test -race ./...
6+
7+
# We verify for the maximum version of the go directive as 1.20
8+
# here because the oldest go directive that exists on our supported
9+
# release branches in k/k is 1.20.
10+
verify:
11+
./hack/verify-examples.sh
12+
./hack/verify-go-directive.sh 1.20

v2/hack/verify-examples.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ if ! git diff --quiet HEAD; then
1818
exit 1
1919
fi
2020

21-
echo "Running tests..."
22-
go test ./examples/...
23-
21+
echo "Running ./examples/tracer"
2422
rm ./examples/tracer/testdata/simple/out.txt
2523
go run ./examples/tracer ./examples/tracer/testdata/simple > ./examples/tracer/testdata/simple/out.txt
2624
if ! git diff --quiet HEAD; then
@@ -29,6 +27,7 @@ if ! git diff --quiet HEAD; then
2927
exit 1
3028
fi
3129

30+
echo "Running ./examples/kilroy"
3231
rm ./examples/kilroy/testdata/simple/generated.kilroy.go
3332
go run ./examples/kilroy/ ./examples/kilroy/testdata/simple
3433
if ! git diff --quiet HEAD; then
@@ -37,6 +36,7 @@ if ! git diff --quiet HEAD; then
3736
exit 1
3837
fi
3938

39+
echo "Running ./examples/pointuh"
4040
rm -rf ./examples/pointuh/testdata/results
4141
go run ./examples/pointuh/ \
4242
--output-dir ./examples/pointuh/testdata/results \

v2/hack/verify-go-directive.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
function usage {
22+
local script="$(basename $0)"
23+
24+
echo >&2 "Usage: ${script} <maximum go directive>
25+
This script should be run at the root of a module.
26+
27+
Compare the go directive in the local working copy's go.mod
28+
to the specified maximum version it can be. Versions provided
29+
here are of the form 1.x.y, without the 'go' prefix.
30+
Examples:
31+
${script} 1.20
32+
${script} 1.21.6
33+
"
34+
exit 1
35+
}
36+
37+
max="$1"
38+
# If max is empty, print usage and error
39+
if [[ -z "${max}" ]]; then
40+
usage;
41+
fi
42+
43+
# Don't specify the version with the go prefix, just 1.x.y will do.
44+
if [[ ! "${max}" =~ ^[0-9]\.[0-9]+(\.[0-9]+)?$ ]]; then
45+
usage
46+
fi
47+
48+
current=$(awk '/^go / {print $2;}' go.mod)
49+
if [[ -z "${current}" ]]; then
50+
echo >&2 "FAIL: could not get value of go directive from go.mod"
51+
exit 1
52+
fi
53+
54+
if ! printf '%s\n' "${current}" "${max}" | sort --check=silent --version-sort; then
55+
echo >&2 "FAIL: current Go directive ${current} is greater than ${max}"
56+
exit 1
57+
fi

0 commit comments

Comments
 (0)