From 798fdbcd2597bbaf86081f950b9bfebcad0d7ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Fri, 14 Jun 2019 18:12:52 +0200 Subject: [PATCH] feat(build.sh) - Add mandatory license check We could decide to make that optional, too, if this is coming into the way. --- hack/build-flags.sh | 14 ++++++++++++++ hack/build.sh | 32 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hack/build-flags.sh b/hack/build-flags.sh index 99cc74ad3f..70412354a9 100644 --- a/hack/build-flags.sh +++ b/hack/build-flags.sh @@ -1,3 +1,17 @@ +# Copyright 2019 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + function build_flags() { local base="${1}" local now="$(date -u '+%Y-%m-%d %H:%M:%S')" diff --git a/hack/build.sh b/hack/build.sh index e83ed6fd0b..a5f5919ca6 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -61,7 +61,10 @@ run() { # Format source code go_fmt - # Generate docs + # Check for license headers + check_license + + # Auto generate cli docs generate_docs fi @@ -98,6 +101,33 @@ go_test() { rm $test_output } +check_license() { + echo "βš–οΈ License" + local required_keywords=("Authors" "Apache License" "LICENSE-2.0") + local extensions_to_check=("sh" "go" "yaml" "yml" "json") + + local check_output=$(mktemp /tmp/kn-client-licence-check.XXXXXX) + for ext in "${extensions_to_check[@]}"; do + find . -name "*.$ext" -a \! -path "./vendor/*" -a \! -path "./.*" -print0 | + while IFS= read -r -d '' path; do + for rword in "${required_keywords[@]}"; do + if ! grep -q "$rword" "$path"; then + echo " $path" >> $check_output + fi + done + done + done + if [ -s $check_output ]; then + echo "πŸ”₯ No license header found in:" + cat $check_output | sort | uniq + echo "πŸ”₯ Please fix and retry." + rm $check_output + exit 1 + fi + rm $check_output +} + + update_deps() { echo "πŸ•ΈοΈ Update" go mod vendor