Skip to content

Commit

Permalink
Add check-license-headers. (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
chowchow316 authored and qiwzhang committed Apr 20, 2017
1 parent fa570a5 commit 68964bd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions mixerclient/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ install:
- ./bazel-installer.sh --user

script:
- script/check-license-headers
- script/check-style
- bazel test :all
- bazel test --config=asan :all
Expand Down
1 change: 1 addition & 0 deletions mixerclient/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mainFlow(utils) {
def presubmit(gitUtils, bazel) {
defaultNode(gitUtils) {
stage('Code Check') {
sh('script/check-license-headers')
sh('script/check-style')
}
}
Expand Down
57 changes: 57 additions & 0 deletions mixerclient/script/check-license-headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
#
# Copyright 2017 Istio Authors. All Rights Reserved.
#
# 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.
#
################################################################################
#
# Checks the source code files for proper license headers.

ISTIO_COPYRIGHT='Copyright 20[0-9][0-9] Istio Authors\. All Rights Reserved\.'
ISTIO_LICENSE='Apache License, Version 2\.0'

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

function is_source_code_file() {
first_line="$(head -1 ${1} | xargs --null)"
filename="$(basename ${1})"
[[ "${filename}" == 'BUILD' ]] && return 0
[[ "${first_line}" == '#!/bin/bash' ]] && return 0
extension="$(echo ${1} | awk -F . '{if (NF>1) {print $NF}}')"
[[ "${extension}" == "c" ||
"${extension}" == "cc" ||
"${extension}" == "h" ||
"${extension}" == "py" ||
"${extension}" == "go" ||
"${extension}" == "bzl" ]] && return 0
return 1
}

BAD_LICENSE=0

for file in $(git ls-files)
do
base="$(echo ${file} | awk -F / '{print $1}')"
[[ "${base}" == "contrib" || "${base}" == "google" || "${base}" == "third_party" ]] && continue
if is_source_code_file "${file}"; then
istio_copyright_count="$(head -n 20 ${file} | grep "${ISTIO_COPYRIGHT}" | wc -l)"
istio_license_count="$(head -n 20 ${file} | grep "${ISTIO_LICENSE}" | wc -l)"
if [[ "${istio_copyright_count}" != 1 || "${istio_license_count}" != 1 ]]; then
echo ${file}
BAD_LICENSE=1
fi
fi
done

[[ ${BAD_LICENSE} == 0 ]] || echo "have invalid license headers".

0 comments on commit 68964bd

Please sign in to comment.