Skip to content

Commit

Permalink
Add license check step to Travis
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Michalak <[email protected]>
Signed-off-by: Tim 'mithro' Ansell <[email protected]>
  • Loading branch information
tmichalak authored and mithro committed May 26, 2020
1 parent c66f4f4 commit 631b07b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/check_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

echo
echo "==========================="
echo "Check SPDX identifier"
echo "==========================="
echo

ERROR_FILES=""
FILES_TO_CHECK=`find . \
-size +0 -type f \( -name '*.sh' -o -name '*.py' -o -name 'Makefile' -o -name '*.tcl' \) \
\( -not -path "*/.*/*" -not -path "*/third_party/*" -not -path "*/database/*" -not -path "*/env/*" \)`

for file in $FILES_TO_CHECK; do
echo "Checking $file"
grep -q "SPDX-License-Identifier" $file || ERROR_FILES="$ERROR_FILES $file"
done

if [ ! -z "$ERROR_FILES" ]; then
for file in $ERROR_FILES; do
echo "ERROR: $file does not have license information."
done
return 1
fi

echo
echo "==========================="
echo "Check third party LICENSE"
echo "==========================="
echo

function check_if_submodule {
for submodule in `git submodule --quiet foreach 'echo $sm_path'`; do
if [ "$1" == "$submodule" ]; then
return 1
fi
done
}

THIRD_PARTY_DIRS=""
if [[ -e third_party ]]; then
THIRD_PARTY_DIRS=`ls third_party --ignore=reformat.tcl --ignore cctz --ignore gflags --ignore yosys `
fi
ERROR_NO_LICENSE=""

for dir in $THIRD_PARTY_DIRS; do
# Checks if we are not in a submodule
if check_if_submodule $dir; then
echo "Checking third_party/$dir"
[ -f third_party/$dir/LICENSE ] || ERROR_NO_LICENSE="$ERROR_NO_LICENSE $dir"
fi
done

if [ ! -z "$ERROR_NO_LICENSE" ]; then
for dir in $ERROR_NO_LICENSE; do
echo "ERROR: $dir does not have the LICENSE file."
done
return 1
fi
37 changes: 37 additions & 0 deletions .github/check_python_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

echo
echo "==================================="
echo "Check python utf coding and shebang"
echo "==================================="
echo

ERROR_FILES_SHEBANG=""
ERROR_FILES_UTF_CODING=""
FILES_TO_CHECK=`find . \
-size +0 -type f \( -name '*.py' \) \
\( -not -path "*/.*/*" -not -path "*/third_party/*" -not -path "*/env/*" \)`

for file in $FILES_TO_CHECK; do
echo "Checking $file"
if [[ -x $file ]]; then
grep -q "\#\!/usr/bin/env python3" $file || ERROR_FILES_SHEBANG="$ERROR_FILES_SHEBANG $file"
fi
grep -q "\#.*coding: utf-8" $file || ERROR_FILES_UTF_CODING="$ERROR_FILES_UTF_CODING $file"
done

if [ ! -z "$ERROR_FILES_SHEBANG" ]; then
for file in $ERROR_FILES_SHEBANG; do
echo "ERROR: $file does not have the python3 shebang."
done
return 1
fi

if [ ! -z "$ERROR_FILES_UTF_CODING" ]; then
for file in $ERROR_FILES_UTF_CODING; do
echo "ERROR: $file does not have the utf encoding set."
done
return 1
fi

echo
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ jobs:
script:
- make format
- test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; }

- name: "License Checks"
script:
- source .github/check_license.sh
- source .github/check_python_scripts.sh

0 comments on commit 631b07b

Please sign in to comment.