Skip to content

Commit 2a03918

Browse files
committed
travis: license check for new files
Fail if new file does not contain SPDX identifier. We only checked for changed files, and warn. This is not sufficient because new files should follow our license guide. It could have been overlooked. This fixes the problem.
1 parent 5940b16 commit 2a03918

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

.travis.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,46 @@ matrix:
6464
- pip install scancode-toolkit==3.1.1
6565
before_script:
6666
- mkdir -p SCANCODE
67+
- mkdir -p SCANCODE_NEW_FILES
6768
# Fetch remaining information needed for branch comparison
6869
- git fetch --all --unshallow --tags
6970
- git fetch origin "${TRAVIS_BRANCH}"
7071
script:
7172
# scancode does not support list of files, only one file or directory
7273
# we use SCANCODE directory for all changed files (their copies with full tree)
7374
- >-
74-
git diff --name-only --diff-filter=d FETCH_HEAD..HEAD \
75+
git diff --name-only --diff-filter=ad FETCH_HEAD..HEAD \
7576
| ( grep '.\(c\|cpp\|h\|hpp\|py\)$' || true ) \
7677
| ( grep -v '^tools/test/toolchains/api_test.py' || true ) \
7778
| while read file; do cp --parents "${file}" SCANCODE; done
7879
- scancode -l --json-pp scancode.json SCANCODE
7980
- python ./tools/test/travis-ci/scancode-evaluate.py -f scancode.json || true
81+
# run the same but for new files. All new files must have SPDX
82+
- >-
83+
git diff --name-only --diff-filter=A FETCH_HEAD..HEAD \
84+
| ( grep '.\(c\|cpp\|h\|hpp\|py\)$' || true ) \
85+
| ( grep -v '^tools/test/toolchains/api_test.py' || true ) \
86+
| while read file; do cp --parents "${file}" SCANCODE_NEW_FILES; done
87+
- scancode -l --json-pp scancode_new_files.json SCANCODE_NEW_FILES
88+
- python ./tools/test/travis-ci/scancode-evaluate.py -f scancode_new_files.json || true
8089
after_success:
8190
- python ./tools/test/travis-ci/scancode-evaluate.py -f scancode.json
8291
- cat scancode-evaluate.log
8392
- COUNT=$(cat scancode-evaluate.log | grep 'File:' | wc -l)
93+
- python ./tools/test/travis-ci/scancode-evaluate.py -f scancode_new_files.json
94+
- cat scancode-evaluate.log
95+
- COUNT_NEW_FILES=$(cat scancode-evaluate.log | grep 'File:' | wc -l)
8496
- |
85-
if [ $COUNT == 0 ]; then
97+
if [ $COUNT == 0 && $COUNT_NEW_FILES == 0 ]; then
8698
echo "License check OK";
8799
STATUSM="All licenses OK";
88100
set_status "success" "$STATUSM";
101+
elif [ $COUNT_NEW_FILES != 0 ]; then
102+
echo "License check failed, new files with the license issues found";
103+
STATUSM="Needs review, ${COUNT} license issues found";
104+
set_status "failure" "$STATUSM";
89105
else
90-
echo "License check failed, please review license issues found";
106+
echo "License check failed, please review license issues found in modified files";
91107
STATUSM="Needs review, ${COUNT} license issues found";
92108
set_status "success" "$STATUSM";
93109
fi

0 commit comments

Comments
 (0)