Skip to content

Commit 45b1013

Browse files
crmejiaarschles
authored andcommitted
make verify validates that versioned APIs contain json tags for fields, addresses openshift#1303 (openshift#1480)
* initial verification * added description, removed comments and unnecesarry code * improved to add line numbers. Also comment format. * Replaced tail with sed
1 parent 0ee8398 commit 45b1013

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ verify: .init .generate_files verify-generated verify-client-gen
220220
@$(DOCKER_CMD) verify-links.sh -t $(SKIP_HTTP) .
221221
@echo Running errexit checker:
222222
@$(DOCKER_CMD) build/verify-errexit.sh
223+
@echo Running tag verification:
224+
@$(DOCKER_CMD) build/verify-tags.sh
223225

224226
verify-generated: .init .generate_files
225227
$(DOCKER_CMD) $(BUILD_DIR)/update-apiserver-gen.sh --verify-only

Diff for: build/verify-tags.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Copyright 2014 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+
# This script makes sure each versioned API in service catalog
18+
#has as json tag
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
result=0
25+
26+
find_files() {
27+
find . -not \( \
28+
\( \
29+
-wholename './output' \
30+
-o -wholename './_gopath' \
31+
-o -wholename './release' \
32+
-o -wholename './target' \
33+
-o -wholename '*/vendor/*' \
34+
\) -prune \
35+
\) \
36+
\( -wholename '*pkg/api/v*/types.go' \
37+
-o -wholename '*pkg/apis/*/v*/types.go' \
38+
-o -wholename '*pkg/api/unversioned/types.go' \
39+
\)
40+
}
41+
42+
if [[ $# -eq 0 ]]; then
43+
versioned_api_files=$(find_files | egrep "pkg/(.[^/]*)+/((v.[^/]*)|unversioned)/types\.go")
44+
else
45+
versioned_api_files="${*}"
46+
fi
47+
48+
for file in $versioned_api_files; do
49+
if cat -n "${file}" | sed -n '/genclient/,$p' | grep -v "^\s*[0-9]*\s$" | egrep -v "(\/\/|{|}|\(|\)|type|=)" | grep -v json; then
50+
echo "Versioned APIs should contain json tags for fields in file ${file}"
51+
result=1
52+
fi
53+
done
54+
exit ${result}

0 commit comments

Comments
 (0)