|
| 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