Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build.sh) - Add mandatory license check #187

Merged
merged 1 commit into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point...

BTW, should we move go_fmt before compile and test? I hate the idea of the compiled and tested code being changed after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We can do this, and as the --fast mode skips formatting anyway it doesn't matter whether it is skipped before or after compile ;-)


# 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