Skip to content

Commit 765e3e3

Browse files
committed
add download mechanism for required tools, update verify logic
On-behalf-of: @SAP [email protected]
1 parent 49f4a41 commit 765e3e3

File tree

7 files changed

+272
-4
lines changed

7 files changed

+272
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/_build/
2+
/_tools/
23
/vendor/
34
.cover
45
*.kubeconfig

.wwhrd.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ allowlist:
2727
- ISC
2828

2929
exceptions:
30-
- github.com/muhlemmer/gu # public domain, required for zitadel/oidc
30+
- github.com/hashicorp/golang-lru/v2 # MPL 2.0
31+
- github.com/hashicorp/golang-lru/v2/internal # MPL 2.0
32+
- github.com/hashicorp/golang-lru/v2/simplelru # MPL 2.0
3133
- github.com/hashicorp/hcl # MPL 2.0
3234
- github.com/hashicorp/hcl/hcl/ast # MPL 2.0
3335
- github.com/hashicorp/hcl/hcl/parser # MPL 2.0

Makefile

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ LDFLAGS += -extldflags '-static' \
2424
-X github.com/kcp-dev/api-syncagent/internal/version.gitHead=$(GIT_HEAD)
2525
BUILD_DEST ?= _build
2626
GOTOOLFLAGS ?= $(GOBUILDFLAGS) -ldflags '-w $(LDFLAGS)' $(GOTOOLFLAGS_EXTRA)
27+
GOARCH ?= $(shell go env GOARCH)
28+
GOOS ?= $(shell go env GOOS)
2729

2830
.PHONY: all
2931
all: build test
@@ -37,6 +39,47 @@ $(CMD): %: $(BUILD_DEST)/%
3739
$(BUILD_DEST)/%: cmd/%
3840
go build $(GOTOOLFLAGS) -o $@ ./cmd/$*
3941

42+
GOLANGCI_LINT = _tools/golangci-lint
43+
GOLANGCI_LINT_VERSION = 1.63.4
44+
45+
.PHONY: $(GOLANGCI_LINT)
46+
$(GOLANGCI_LINT):
47+
@hack/download-tool.sh \
48+
https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-${GOOS}-${GOARCH}.tar.gz \
49+
golangci-lint \
50+
${GOLANGCI_LINT_VERSION}
51+
52+
GIMPS = _tools/gimps
53+
GIMPS_VERSION = 0.6.0
54+
55+
.PHONY: $(GIMPS)
56+
$(GIMPS):
57+
@hack/download-tool.sh \
58+
https://github.com/xrstf/gimps/releases/download/v${GIMPS_VERSION}/gimps_${GIMPS_VERSION}_${GOOS}_${GOARCH}.tar.gz \
59+
gimps \
60+
${GIMPS_VERSION}
61+
62+
WWHRD = _tools/wwhrd
63+
WWHRD_VERSION = 0.4.0
64+
65+
.PHONY: $(WWHRD)
66+
$(WWHRD):
67+
@hack/download-tool.sh \
68+
https://github.com/frapposelli/wwhrd/releases/download/v${WWHRD_VERSION}/wwhrd_${WWHRD_VERSION}_${GOOS}_${GOARCH}.tar.gz \
69+
wwhrd \
70+
${WWHRD_VERSION} \
71+
wwhrd
72+
73+
BOILERPLATE = _tools/boilerplate
74+
BOILERPLATE_VERSION = 0.3.0
75+
76+
.PHONY: $(BOILERPLATE)
77+
$(BOILERPLATE):
78+
@hack/download-tool.sh \
79+
https://github.com/kubermatic-labs/boilerplate/releases/download/v${BOILERPLATE_VERSION}/boilerplate_${BOILERPLATE_VERSION}_${GOOS}_${GOARCH}.tar.gz \
80+
boilerplate \
81+
${BOILERPLATE_VERSION}
82+
4083
.PHONY: test
4184
test:
4285
./hack/run-tests.sh
@@ -56,14 +99,17 @@ clean:
5699
@echo "Cleaned $(BUILD_DEST)"
57100

58101
.PHONY: lint
59-
lint:
60-
golangci-lint run \
102+
lint: $(GOLANGCI_LINT)
103+
$(GOLANGCI_LINT) run \
61104
--verbose \
62105
--print-resources-usage \
63106
./...
64107

108+
.PHONY: imports
109+
imports: $(GIMPS)
110+
$(GIMPS) .
111+
65112
.PHONY: verify
66113
verify:
67114
./hack/verify-boilerplate.sh
68-
./hack/verify-import-order.sh
69115
./hack/verify-licenses.sh

hack/ci/verify.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The KCP 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 -euo pipefail
18+
19+
cd $(dirname $0)/../..
20+
source hack/lib.sh
21+
22+
EXIT_CODE=0
23+
24+
try() {
25+
local title="$1"
26+
shift
27+
28+
heading "$title"
29+
echo -e "$@\n"
30+
31+
start_time=$(date +%s)
32+
33+
set +e
34+
$@
35+
exitCode=$?
36+
set -e
37+
38+
elapsed_time=$(($(date +%s) - $start_time))
39+
TEST_NAME="$title" write_junit $exitCode "$elapsed_time"
40+
41+
if [[ $exitCode -eq 0 ]]; then
42+
echo -e "\n[${elapsed_time}s] SUCCESS :)"
43+
else
44+
echo -e "\n[${elapsed_time}s] FAILED."
45+
EXIT_CODE=1
46+
fi
47+
48+
git reset --hard --quiet
49+
git clean --force
50+
51+
echo
52+
}
53+
54+
verify_codegen() {
55+
make codegen
56+
57+
echo "Diffing…"
58+
if ! git diff --exit-code deploy internal sdk; then
59+
echo "The generated code / CRDs are out of date. Please run 'make codegen'."
60+
return 1
61+
fi
62+
63+
echo "The generated code / CRDs is up to date."
64+
}
65+
66+
verify_gomod() {
67+
go mod tidy
68+
go mod verify
69+
git diff --exit-code
70+
}
71+
72+
verify_imports() {
73+
make imports
74+
75+
echo "Diffing…"
76+
if ! git diff --exit-code; then
77+
echo "Some import statements are not properly grouped. Please run 'make imports'."
78+
return 1
79+
fi
80+
81+
echo "Your Go import statements are in order :-)"
82+
}
83+
84+
try "Verify code generation" verify_codegen
85+
try "Verify go.mod" verify_gomod
86+
try "Verify Go imports" verify_imports
87+
try "Verify license compatibility" ./hack/verify-licenses.sh
88+
try "Verify boilerplate" ./hack/verify-boilerplate.sh
89+
90+
exit $EXIT_CODE

hack/download-tool.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The KCP 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 -euo pipefail
18+
19+
cd $(dirname $0)/..
20+
source hack/lib.sh
21+
22+
mkdir -p _tools
23+
cd _tools
24+
25+
URL="$1"
26+
BINARY="$2"
27+
VERSION="$3"
28+
BINARY_PATTERN="${4:-**/$BINARY}"
29+
30+
# Check if and what version we installed already.
31+
versionFile="$BINARY.version"
32+
existingVersion=""
33+
if [ -f "$versionFile" ]; then
34+
existingVersion="$(cat "$versionFile")"
35+
fi
36+
37+
# If the binary exists and its version matches, we're good.
38+
if [ -f "$BINARY" ] && [ "$VERSION" == "$existingVersion" ]; then
39+
exit 0
40+
fi
41+
42+
(
43+
rm -rf tmp
44+
mkdir -p tmp
45+
cd tmp
46+
47+
echo "Downloading $BINARY" >&2
48+
curl --fail -LO "$URL"
49+
archive="$(ls)"
50+
51+
case "$archive" in
52+
*.tar.gz | *.tgz)
53+
tar xzf "$archive"
54+
;;
55+
*.zip)
56+
unzip "$archive"
57+
;;
58+
*)
59+
echo "Unknown file type: $archive" >&2
60+
exit 1
61+
esac
62+
63+
mv $BINARY_PATTERN ../$BINARY
64+
chmod +x ../$BINARY
65+
)
66+
67+
rm -rf tmp
68+
echo "$VERSION" > "$versionFile"
69+
70+
echo "Installed $BINARY version $VERSION." >&2

hack/verify-boilerplate.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The KCP 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 -euo pipefail
18+
19+
cd $(dirname $0)/..
20+
source hack/lib.sh
21+
22+
make --no-print-directory _tools/boilerplate
23+
24+
echo "Checking file boilerplates…"
25+
_tools/boilerplate \
26+
-boilerplates hack/boilerplate \
27+
-exclude .github \
28+
-exclude internal/certificates/triple \
29+
-exclude sdk/clientset \
30+
-exclude sdk/informers \
31+
-exclude sdk/listers

hack/verify-licenses.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The KCP 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 -euo pipefail
18+
19+
cd $(dirname $0)/..
20+
source hack/lib.sh
21+
22+
make --no-print-directory _tools/wwhrd
23+
24+
go mod vendor
25+
26+
echo "Checking licenses…"
27+
_tools/wwhrd check -q
28+
echo "Check successful."

0 commit comments

Comments
 (0)