Skip to content

Commit 676802f

Browse files
author
Martijn The
committed
Test
1 parent 8aa06c8 commit 676802f

File tree

4 files changed

+196
-1
lines changed

4 files changed

+196
-1
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
yarn-error.log
3+
.idea

Diff for: .travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ cache:
1111
jobs:
1212
include:
1313
- stage: lint
14-
script: yarn lint
14+
script:
15+
- ./tools/check-signed-off.sh
16+
- ./tools/check-license.py
17+
- yarn lint
1518
- stage: build
1619
script: yarn prepare
1720
- stage: test

Diff for: tools/check-license.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright JS Foundation and other contributors, http://js.foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import print_function
18+
19+
import os
20+
import re
21+
import sys
22+
23+
LICENSE = re.compile(
24+
r'((#|//|\*) Copyright .*\n'
25+
r')+\s?\2\n'
26+
r'\s?\2 Licensed under the Apache License, Version 2.0 \(the "License"\);\n'
27+
r'\s?\2 you may not use this file except in compliance with the License.\n'
28+
r'\s?\2 You may obtain a copy of the License at\n'
29+
r'\s?\2\n'
30+
r'\s?\2 http://www.apache.org/licenses/LICENSE-2.0\n'
31+
r'\s?\2\n'
32+
r'\s?\2 Unless required by applicable law or agreed to in writing, software\n'
33+
r'\s?\2 distributed under the License is distributed on an "AS IS" BASIS\n'
34+
r'\s?\2 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
35+
r'\s?\2 See the License for the specific language governing permissions and\n'
36+
r'\s?\2 limitations under the License.\n'
37+
)
38+
39+
INCLUDE_DIRS = [
40+
'src',
41+
'tools',
42+
]
43+
44+
EXCLUDE_DIRS = [
45+
]
46+
47+
EXTENSIONS = [
48+
'.c',
49+
'.cmake',
50+
'.cpp',
51+
'.h',
52+
'.js',
53+
'.py',
54+
'.S',
55+
'.sh',
56+
'.tcl',
57+
'.ts',
58+
]
59+
60+
61+
def main():
62+
is_ok = True
63+
64+
for dname in INCLUDE_DIRS:
65+
for root, _, files in os.walk(dname):
66+
if any(root.startswith(exclude) for exclude in EXCLUDE_DIRS):
67+
continue
68+
for fname in files:
69+
if any(fname.endswith(ext) for ext in EXTENSIONS):
70+
fpath = os.path.join(root, fname)
71+
with open(fpath) as curr_file:
72+
if not LICENSE.search(curr_file.read()):
73+
print('%s: incorrect license' % fpath)
74+
is_ok = False
75+
76+
if not is_ok:
77+
sys.exit(1)
78+
79+
80+
if __name__ == '__main__':
81+
main()

Diff for: tools/check-signed-off.sh

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# Copyright JS Foundation and other contributors, http://js.foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Usage
18+
function print_usage
19+
{
20+
echo "Usage: $0 [--help] [--tolerant] [--travis]"
21+
}
22+
23+
function print_help
24+
{
25+
echo "$0: Check Signed-off-by message of the latest commit"
26+
echo ""
27+
print_usage
28+
echo ""
29+
echo "Optional arguments:"
30+
echo " --help print this help message"
31+
echo " --tolerant check the existence of the message only but don't"
32+
echo " require the name and email address to match the author"
33+
echo " of the commit"
34+
echo " --travis perform check in tolerant mode if on Travis CI and not"
35+
echo " checking a pull request, perform strict check otherwise"
36+
echo ""
37+
echo "The last line of every commit message must follow the form of:"
38+
echo "'JerryScript-DCO-1.0-Signed-off-by: NAME EMAIL', where NAME and EMAIL must"
39+
echo "match the name and email address of the author of the commit (unless in"
40+
echo "tolerant mode)."
41+
}
42+
43+
# Processing command line
44+
TOLERANT="no"
45+
while [ "$#" -gt 0 ]
46+
do
47+
if [ "$1" == "--help" ]
48+
then
49+
print_help
50+
exit 0
51+
elif [ "$1" == "--tolerant" ]
52+
then
53+
TOLERANT="yes"
54+
shift
55+
elif [ "$1" == "--travis" ]
56+
then
57+
if [ "$TRAVIS_PULL_REQUEST" == "" ]
58+
then
59+
echo -e "\e[1;33mWarning! Travis-tolerant mode requested but not running on Travis CI! \e[0m"
60+
elif [ "$TRAVIS_PULL_REQUEST" == "false" ]
61+
then
62+
TOLERANT="yes"
63+
else
64+
TOLERANT="no"
65+
fi
66+
shift
67+
else
68+
print_usage
69+
exit 1
70+
fi
71+
done
72+
73+
# Determining latest commit
74+
parent_hashes=(`git show -s --format=%p HEAD | head -1`)
75+
76+
if [ "${#parent_hashes[@]}" -eq 1 ]
77+
then
78+
commit_hash=`git show -s --format=%h HEAD | head -1`
79+
elif [ "${#parent_hashes[@]}" -eq 2 ]
80+
then
81+
commit_hash=${parent_hashes[1]}
82+
else
83+
echo "$0: cannot handle commit with ${#parent_hashes[@]} parents ${parent_hashes[@]}"
84+
exit 1
85+
fi
86+
87+
# Checking the last line
88+
actual_signed_off_by_line=`git show -s --format=%B $commit_hash | sed '/^$/d' | tr -d '\015' | tail -n 1`
89+
90+
if [ "$TOLERANT" == "no" ]
91+
then
92+
author_name=`git show -s --format=%an $commit_hash`
93+
author_email=`git show -s --format=%ae $commit_hash`
94+
required_signed_off_by_line="JerryScript-DCO-1.0-Signed-off-by: $author_name $author_email"
95+
96+
if [ "$actual_signed_off_by_line" != "$required_signed_off_by_line" ]
97+
then
98+
echo -e "\e[1;33mSigned-off-by message is incorrect. The following line should be at the end of the $commit_hash commit's message: '$required_signed_off_by_line'. \e[0m"
99+
exit 1
100+
fi
101+
else
102+
echo -e "\e[1;33mWarning! The name and email address of the author of the $commit_hash commit is not checked in tolerant mode! \e[0m"
103+
if echo "$actual_signed_off_by_line" | grep -q -v '^JerryScript-DCO-1.0-Signed-off-by:'
104+
then
105+
echo -e "\e[1;33mSigned-off-by message is incorrect. The following line should be at the end of the $commit_hash commit's message: '$required_signed_off_by_line'. \e[0m"
106+
exit 1
107+
fi
108+
fi
109+
110+
exit 0

0 commit comments

Comments
 (0)