Skip to content

Commit

Permalink
feat(build.sh) - Add mandatory license check
Browse files Browse the repository at this point in the history
We could decide to make that optional, too, if this is coming into the way.
  • Loading branch information
rhuss committed Jun 14, 2019
1 parent 5d26faa commit 798fdbc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
14 changes: 14 additions & 0 deletions hack/build-flags.sh
Original file line number Diff line number Diff line change
@@ -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')"
Expand Down
32 changes: 31 additions & 1 deletion hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 798fdbc

Please sign in to comment.