...

Text file src/k8s.io/kubernetes/hack/verify-description.sh

Documentation: k8s.io/kubernetes/hack

     1#!/usr/bin/env 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 checks API-related files for missing descriptions and outputs a
    18# list of structs and fields that are missing descriptions.
    19# Usage: `hack/verify-description.sh`.
    20
    21set -o errexit
    22set -o nounset
    23set -o pipefail
    24
    25KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
    26source "${KUBE_ROOT}/hack/lib/init.sh"
    27source "${KUBE_ROOT}/hack/lib/util.sh"
    28
    29kube::golang::setup_env
    30
    31GOPROXY=off go install ./cmd/genswaggertypedocs
    32
    33find_files() {
    34  find . -not \( \
    35      \( \
    36        -wholename '.git' \
    37        -o -wholename './_output' \
    38        -o -wholename './release' \
    39        -o -wholename './target' \
    40        -o -wholename '*/third_party/*' \
    41        -o -wholename '*/vendor/*' \
    42        -o -wholename './pkg/*' \
    43      \) -prune \
    44    \) \
    45    \( -wholename './staging/src/k8s.io/api/*/v*/types.go' \
    46       -o -wholename './staging/src/k8s.io/kube-aggregator/pkg/apis/*/v*/types.go' \
    47       -o -wholename './staging/src/k8s.io/apiextensions-apiserver/pkg/apis/*/v*/types.go' \
    48    \)
    49}
    50
    51if [[ $# -eq 0 ]]; then
    52  versioned_api_files=$(find_files) || true
    53else
    54  versioned_api_files="${*}"
    55fi
    56
    57# find_files had incorrect regexes which led to genswaggertypedocs never being invoked.
    58# This led to many types.go have missing descriptions.
    59# These types.go files are listed in hack/.descriptions_failures
    60# Check that the file is in alphabetical order
    61failure_file="${KUBE_ROOT}/hack/.descriptions_failures"
    62kube::util::check-file-in-alphabetical-order "${failure_file}"
    63
    64failing_files=()
    65while IFS='' read -r line; do failing_files+=("$line"); done < <(cat "$failure_file")
    66
    67result=0
    68for file in $versioned_api_files; do
    69  if ! kube::util::array_contains "$file" "${failing_files[@]}"; then
    70    gen_swagger_result=0
    71    genswaggertypedocs -v -s "${file}" -f - || gen_swagger_result=$?
    72    if [[ "${gen_swagger_result}" -ne 0 ]]; then
    73      echo "API file: ${file} is missing: ${gen_swagger_result} descriptions"
    74      result=1
    75    fi
    76  fi
    77
    78  if grep json: "${file}" | grep -v // | grep description: ; then
    79    echo "API file: ${file} should not contain descriptions in struct tags"
    80    result=1
    81  fi
    82  if grep json: "${file}" | grep -Ee ",[[:space:]]+omitempty|omitempty[[:space:]]+" ; then
    83    echo "API file: ${file} should not contain leading or trailing spaces for omitempty directive"
    84    result=1
    85  fi
    86done
    87
    88internal_types_files="${KUBE_ROOT}/pkg/apis/core/types.go ${KUBE_ROOT}/pkg/apis/extensions/types.go"
    89for internal_types_file in $internal_types_files; do
    90  if [[ ! -e $internal_types_file ]]; then
    91    echo "Internal types file ${internal_types_file} does not exist"
    92    result=1
    93    continue
    94  fi
    95
    96  if grep json: "${internal_types_file}" | grep -v // | grep description: ; then
    97    echo "Internal API types should not contain descriptions"
    98    result=1
    99  fi
   100done
   101
   102exit ${result}

View as plain text