-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make CI enforce correct license banner + correct DCO sign-off in commit message #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
yarn-error.log | ||
.idea | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ cache: | |
jobs: | ||
include: | ||
- stage: lint | ||
script: yarn lint | ||
script: | ||
- ./tools/check-signed-off.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you'll need |
||
- ./tools/check-license.py | ||
- yarn lint | ||
- stage: build | ||
script: yarn prepare | ||
- stage: test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright JS Foundation and other contributors, http://js.foundation | ||
# | ||
# 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. | ||
|
||
from __future__ import print_function | ||
|
||
import os | ||
import re | ||
import sys | ||
|
||
LICENSE = re.compile( | ||
r'((#|//|\*) Copyright .*\n' | ||
r')+\s?\2\n' | ||
r'\s?\2 Licensed under the Apache License, Version 2.0 \(the "License"\);\n' | ||
r'\s?\2 you may not use this file except in compliance with the License.\n' | ||
r'\s?\2 You may obtain a copy of the License at\n' | ||
r'\s?\2\n' | ||
r'\s?\2 http://www.apache.org/licenses/LICENSE-2.0\n' | ||
r'\s?\2\n' | ||
r'\s?\2 Unless required by applicable law or agreed to in writing, software\n' | ||
r'\s?\2 distributed under the License is distributed on an "AS IS" BASIS\n' | ||
r'\s?\2 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' | ||
r'\s?\2 See the License for the specific language governing permissions and\n' | ||
r'\s?\2 limitations under the License.\n' | ||
) | ||
|
||
INCLUDE_DIRS = [ | ||
'src', | ||
'tools', | ||
] | ||
|
||
EXCLUDE_DIRS = [ | ||
] | ||
|
||
EXTENSIONS = [ | ||
'.c', | ||
'.cmake', | ||
'.cpp', | ||
'.h', | ||
'.js', | ||
'.py', | ||
'.S', | ||
'.sh', | ||
'.tcl', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it makes sense to keep these around to catch future additions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I considered it. But most of them only make sense in the context of a C project. I think it makes more sense to just add as needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also voting for the shorter list. For now, something like the following might be needed: .sh, .py, .js, .ts? |
||
'.ts', | ||
] | ||
|
||
|
||
def main(): | ||
is_ok = True | ||
|
||
for dname in INCLUDE_DIRS: | ||
for root, _, files in os.walk(dname): | ||
if any(root.startswith(exclude) for exclude in EXCLUDE_DIRS): | ||
continue | ||
for fname in files: | ||
if any(fname.endswith(ext) for ext in EXTENSIONS): | ||
fpath = os.path.join(root, fname) | ||
with open(fpath) as curr_file: | ||
if not LICENSE.search(curr_file.read()): | ||
print('%s: incorrect license' % fpath) | ||
is_ok = False | ||
|
||
if not is_ok: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
|
||
# Copyright JS Foundation and other contributors, http://js.foundation | ||
# | ||
# 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. | ||
|
||
# Usage | ||
function print_usage | ||
{ | ||
echo "Usage: $0 [--help] [--tolerant] [--travis]" | ||
} | ||
|
||
function print_help | ||
{ | ||
echo "$0: Check Signed-off-by message of the latest commit" | ||
echo "" | ||
print_usage | ||
echo "" | ||
echo "Optional arguments:" | ||
echo " --help print this help message" | ||
echo " --tolerant check the existence of the message only but don't" | ||
echo " require the name and email address to match the author" | ||
echo " of the commit" | ||
echo " --travis perform check in tolerant mode if on Travis CI and not" | ||
echo " checking a pull request, perform strict check otherwise" | ||
echo "" | ||
echo "The last line of every commit message must follow the form of:" | ||
echo "'JerryScript-DCO-1.0-Signed-off-by: NAME EMAIL', where NAME and EMAIL must" | ||
echo "match the name and email address of the author of the commit (unless in" | ||
echo "tolerant mode)." | ||
} | ||
|
||
# Processing command line | ||
TOLERANT="no" | ||
while [ "$#" -gt 0 ] | ||
do | ||
if [ "$1" == "--help" ] | ||
then | ||
print_help | ||
exit 0 | ||
elif [ "$1" == "--tolerant" ] | ||
then | ||
TOLERANT="yes" | ||
shift | ||
elif [ "$1" == "--travis" ] | ||
then | ||
if [ "$TRAVIS_PULL_REQUEST" == "" ] | ||
then | ||
echo -e "\e[1;33mWarning! Travis-tolerant mode requested but not running on Travis CI! \e[0m" | ||
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] | ||
then | ||
TOLERANT="yes" | ||
else | ||
TOLERANT="no" | ||
fi | ||
shift | ||
else | ||
print_usage | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Determining latest commit | ||
parent_hashes=(`git show -s --format=%p HEAD | head -1`) | ||
|
||
if [ "${#parent_hashes[@]}" -eq 1 ] | ||
then | ||
commit_hash=`git show -s --format=%h HEAD | head -1` | ||
elif [ "${#parent_hashes[@]}" -eq 2 ] | ||
then | ||
commit_hash=${parent_hashes[1]} | ||
else | ||
echo "$0: cannot handle commit with ${#parent_hashes[@]} parents ${parent_hashes[@]}" | ||
exit 1 | ||
fi | ||
|
||
# Checking the last line | ||
actual_signed_off_by_line=`git show -s --format=%B $commit_hash | sed '/^$/d' | tr -d '\015' | tail -n 1` | ||
|
||
if [ "$TOLERANT" == "no" ] | ||
then | ||
author_name=`git show -s --format=%an $commit_hash` | ||
author_email=`git show -s --format=%ae $commit_hash` | ||
required_signed_off_by_line="JerryScript-DCO-1.0-Signed-off-by: $author_name $author_email" | ||
|
||
if [ "$actual_signed_off_by_line" != "$required_signed_off_by_line" ] | ||
then | ||
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" | ||
exit 1 | ||
fi | ||
else | ||
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" | ||
if echo "$actual_signed_off_by_line" | grep -q -v '^JerryScript-DCO-1.0-Signed-off-by:' | ||
then | ||
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" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just something you do on your system, might be more appropriate to do something like I do:
In
/home/pepsi/.gitconfig
:In
/home/pepsi/.gitignore_global
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main project's .gitignore has a bunch of IDE related lines:
https://github.com/jerryscript-project/jerryscript/blob/master/.gitignore#L9
I don't feel strongly about it though, although I've got bitten by system-level gitignore in the past where a repo actually did have files that were being ignored by my own system-level gitignore (and touching those files didn't appear as changed). So I've lived with an empty one ever since...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thoughts are with @martijnthe :) I feel alike
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me; I'd never seen .idea before. :)